/*
 *	Name:	smeta_exploit.c
 *
 *	Purpose:
 *	Source file containing the functions that use the product metadata to calculate
 *	viewing and solar illumination angles. These functions operate on the SMETA data
 *      type defined in "smeta.h".
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "ias_logging.h"
#include "ias_math.h"
#include "ias_odl.h"				/* ODL access routines for reading metadata  */
#include "ias_geo.h"				/* NOVAS calls for sun angle computation     */
#include "smeta_exploit.h"			/* Definition of SMETA structure and
						   function prototypes.                      */

#define	MAX_FIELD_NAME	128			/* Maximum number of characters in an ODL
						   field name in the enhanced metadata file  */

int smeta_read(
    SMETA	*smeta,				/* Product metadata structure to load        */
    const char	*smeta_filename )		/* Input file name to read                   */
{
    IAS_OBJ_DESC	*smeta_odl;		/* Product metadata ODL object               */
    int		i;				/* Loop index                                */

    /* Open file */
    smeta_odl = ias_odl_read_tree( smeta_filename );
    if ( smeta_odl == NULL )
    {
        IAS_LOG_ERROR("Opening input metadata file %s.", smeta_filename);
        return(ERROR);
    }

    /* Read data */
    /* File information group */
    if ( smeta_read_file_header( smeta, smeta_odl ) != SUCCESS )
    {
        IAS_LOG_ERROR("Reading PRODUCT_METADATA group from %s.", smeta_filename);
        ias_odl_free_tree( smeta_odl );
        return(ERROR);
    }

    /* Projection information group */
    if ( smeta_read_projection( &smeta->projection, smeta_odl ) != SUCCESS )
    {
        IAS_LOG_ERROR("Reading PROJECTION_PARAMETERS group from %s.", smeta_filename);
        ias_odl_free_tree( smeta_odl );
        return(ERROR);
    }

    /* Band information */
    for ( i=0; i<smeta->num_band; i++ )
    {
        if (smeta->sensor_id == IAS_OLI_TIRS)
        {
            smeta_read_band_meta( &smeta->band_smeta[i], smeta_odl );
            smeta_load_band_model( &smeta->band_smeta[i] );
        }
        else if ( (smeta->sensor_id == IAS_ETM) || (smeta->sensor_id == IAS_TM) )/* for Landsat 5 and older sensors */
        {
            smeta_read_band_meta_ls( &smeta->band_smeta_ls[i], smeta_odl );
            smeta_load_band_model_ls( smeta, &smeta->band_smeta_ls[i] );
        }
        else
        {
            IAS_LOG_ERROR("Reading sensor_id %d.", smeta->sensor_id);
            ias_odl_free_tree( smeta_odl );
            return(ERROR);
        }
    }

    /* Release the ODL structure */
    ias_odl_free_tree( smeta_odl );

    return(SUCCESS);
}

int smeta_read_file_header(
    SMETA		*smeta,			/* Product metadata structure to load       */
    IAS_OBJ_DESC        *smeta_odl )		/* Product metadata ODL object              */
{
    int		i;				/* Loop index                               */
    int		count;				/* Counter for ODL read routines            */
    char	fname[MAX_FIELD_NAME];		/* Band file field names                    */
    char	bname[MAX_FIELD_NAME];		/* Band file names                          */
    char	str[MAX_FIELD_NAME];		/* file names                          */

    /* Read data */
    /* File information fields */
    if ( ias_odl_get_field( smeta->scene_id, sizeof(smeta->scene_id), IAS_ODL_String, smeta_odl,
                            "METADATA_FILE_INFO", "LANDSAT_SCENE_ID", &count ) != SUCCESS )
    {
        IAS_LOG_ERROR("Reading LANDSAT_SCENE_ID from PRODUCT_METADATA group.");
        return(ERROR);
    }
    if ( ias_odl_get_field( &smeta->wrs_path, sizeof(int), IAS_ODL_Int, smeta_odl,
                            "PRODUCT_METADATA", "WRS_PATH", &count ) != SUCCESS )
    {
        IAS_LOG_ERROR("Reading WRS_PATH from PRODUCT_METADATA group.");
        return(ERROR);
    }
    if ( ias_odl_get_field( &smeta->wrs_row, sizeof(int), IAS_ODL_Int, smeta_odl,
                            "PRODUCT_METADATA", "WRS_ROW", &count ) != SUCCESS )
    {
        IAS_LOG_ERROR("Reading WRS_ROW from PRODUCT_METADATA group.");
        return(ERROR);
    }

    /* Read in speacecraft id to handle OLI and older LS sensors little differently */
    if ( ias_odl_get_field( str, sizeof(str), IAS_ODL_String, smeta_odl,
                            "PRODUCT_METADATA", "SPACECRAFT_ID", &count ) != SUCCESS )
    {
        IAS_LOG_ERROR("Reading SPACECRAFT_ID from PRODUCT_METADATA group.");
        return(ERROR);
    }

    if( strcmp(str,"LANDSAT_5") == 0 )
        smeta->spacecraft_id = IAS_L5;
	else if( strcmp(str,"LANDSAT_7") == 0 )
        smeta->spacecraft_id = IAS_L7;
    else if( strcmp(str,"LANDSAT_8") == 0 )
        smeta->spacecraft_id = IAS_L8;
    else
    {
        IAS_LOG_ERROR("Unsupported Landsat SPACECRAFT_ID from PRODUCT_METADATA group.");
        return(ERROR);
    }

    if ( ias_odl_get_field( str, sizeof(str), IAS_ODL_String, smeta_odl,
                            "PRODUCT_METADATA", "SENSOR_ID", &count ) != SUCCESS )
    {
        IAS_LOG_ERROR("Reading SENSOR_ID from PRODUCT_METADATA group.");
        return(ERROR);
    }

    if( strcmp(str,"TM") == 0)
    {
        smeta->sensor_id = IAS_TM;
        smeta->sensor_mode = TM_SAM;
    }
	else if( strcmp(str,"ETM") == 0 )
    {
        smeta->sensor_id = IAS_ETM;
        smeta->sensor_mode = TM_SAM;
    }
    else if( strcmp(str,"OLI_TIRS") == 0 )
    {
        smeta->sensor_id = IAS_OLI_TIRS;
        smeta->sensor_mode = OLI;
    }
    else
    {
        IAS_LOG_ERROR("Unsupported Landsat SENSOR_ID from PRODUCT_METADATA group.");
        return(ERROR);
    }

    if ( (smeta->spacecraft_id == IAS_L5 && smeta->sensor_id == IAS_TM) || smeta->sensor_id == IAS_ETM )
    {
        if ( ias_odl_get_field( str, sizeof(str), IAS_ODL_String, smeta_odl,
                                "PRODUCT_METADATA", "SENSOR_MODE", &count ) != SUCCESS )
        {
            IAS_LOG_ERROR("Reading SENSOR_MODE from PRODUCT_METADATA group.");
            return(ERROR);
        }
        if( strcmp(str,"BUMPER") == 0 )
            smeta->sensor_mode = TM_BUMPER;
    }

	 if ( smeta->sensor_mode == TM_SAM ) printf("SAM mode data!\n");
    if ( smeta->sensor_mode == TM_BUMPER ) printf("Bumper mode data!\n");

    if ( ias_odl_get_field( str, sizeof(str), IAS_ODL_String, smeta_odl,
                            "PRODUCT_METADATA", "DATE_ACQUIRED", &count ) != SUCCESS )
    {
        IAS_LOG_ERROR("Reading DATE_ACQUIRED from PRODUCT_METADATA group.");
        return(ERROR);
    }

    if ( sscanf( str, "%04d-%02d-%02d", &smeta->acq_date[0], &smeta->acq_date[1], &smeta->acq_date[2] ) != 3 )
    {
        IAS_LOG_ERROR("Parsing acquisition date from DATE_ACQUIRED field.");
        return(ERROR);
    }

    printf("spacecraft_id = %d, sensor_id = %d, sensor_mode = %d\n", smeta->spacecraft_id, smeta->sensor_id, smeta->sensor_mode);


    /* We have to count the bands by looking at the product band file names */
    smeta->num_band = 0;
    if (smeta->spacecraft_id == IAS_L8)
        for (i=0; i<IAS_MAX_NBANDS; i++)
        {
            sprintf( fname, "FILE_NAME_BAND_%d", i+1 );
            if ( ias_odl_get_field( bname, sizeof(bname), IAS_ODL_String, smeta_odl,
                                    "PRODUCT_METADATA", fname, &count ) == SUCCESS )
            {
                if ( strlen(bname) > 0 )
                {
                    smeta->band_smeta[smeta->num_band].band = i + 1;
                    smeta->num_band++;
                }
            }
        }
    else
        for (i=0; i<IAS_MAX_NBANDS_LS; i++)
        {
            sprintf( fname, "FILE_NAME_BAND_%d", i+1 );
			if ( (smeta->spacecraft_id == IAS_L7) && ((i+1) == 6) ) sprintf( fname, "FILE_NAME_BAND_%d_VCID_1", i+1 );
            if ( ias_odl_get_field( bname, sizeof(bname), IAS_ODL_String, smeta_odl,
                                    "PRODUCT_METADATA", fname, &count ) == SUCCESS )
            {
                if ( strlen(bname) > 0 )
                {
                    smeta->band_smeta_ls[smeta->num_band].band = i + 1;
                    smeta->num_band++;
                }
            }
        }

    /* For the L4/5 TM sensors, add an extra "optical axis" band for framing purposes. */
    /* This will be suppressed prior to angle band generation. */
    if ( smeta->sensor_id == IAS_TM )
    {
        smeta->band_smeta_ls[smeta->num_band].band = 0;
        smeta->num_band++;
    }

    /* Read the off-nadir roll angle */
    if ( smeta->spacecraft_id == IAS_L8 )
    {
        if ( ias_odl_get_field( &smeta->roll_angle, sizeof(double), IAS_ODL_Double, smeta_odl,
                                "IMAGE_ATTRIBUTES", "ROLL_ANGLE", &count ) != SUCCESS )
        {
            IAS_LOG_ERROR("Reading ROLL_ANGLE from IMAGE_ATTRIBUTES group.");
            smeta->roll_angle = 0.0;
        }
    }
    else
        smeta->roll_angle = 0.0;

    /* Read the scene center sun angles */
    if ( ias_odl_get_field( &smeta->sun_azimuth, sizeof(double), IAS_ODL_Double, smeta_odl,
                            "IMAGE_ATTRIBUTES", "SUN_AZIMUTH", &count ) != SUCCESS )
    {
        IAS_LOG_ERROR("Reading SUN_AZIMUTH from IMAGE_ATTRIBUTES group.");
        return(ERROR);
    }
    if ( ias_odl_get_field( &smeta->sun_elevation, sizeof(double), IAS_ODL_Double, smeta_odl,
                            "IMAGE_ATTRIBUTES", "SUN_ELEVATION", &count ) != SUCCESS )
    {
        IAS_LOG_ERROR("Reading SUN_ELEVATION from IMAGE_ATTRIBUTES group.");
        return(ERROR);
    }

    return(SUCCESS);
}

int smeta_read_projection(
    SMETA_SCENE_PROJ	*projection,		/* Projection structure to load              */
    IAS_OBJ_DESC        *smeta_odl )		/* Enhanced metadata ODL object              */
{
    int		i;				/* Parameter loop index                      */
    char	projname[MAX_FIELD_NAME];	/* Text projection code must be UTM or PS    */
    int		count;				/* Counter for ODL read routines             */

    /* Read data */
    /* Projection information group */
    projection->wgs84_major_axis = 6378137.0;
    projection->wgs84_minor_axis = 6356752.314;
    /* Get the projection code from the metadata and populate default parameters appropriately */
    if ( ias_odl_get_field( projname, sizeof(projname), IAS_ODL_String, smeta_odl,
                            "PROJECTION_PARAMETERS", "MAP_PROJECTION", &count ) != SUCCESS )
    {
        IAS_LOG_ERROR("Reading MAP_PROJECTION from PROJECTION_PARAMETERS group.");
        return(ERROR);
    }
    for (i=0; i<IAS_PROJ_PARAM_SIZE; i++)
        projection->projprms[i] = 0.0;
    if ( strncmp( projname, "UTM", 3 ) == 0 )
    {
        projection->code = 1;
        /* Read zone number if UTM */
        if ( ias_odl_get_field( &projection->zone, sizeof(int), IAS_ODL_Int, smeta_odl,
                                "PROJECTION_PARAMETERS", "UTM_ZONE", &count ) != SUCCESS )
        {
            IAS_LOG_ERROR("Reading UTM_ZONE from PROJECTION_PARAMETERS group.");
            return(ERROR);
        }
    }
    else if ( strncmp( projname, "PS", 2 ) == 0 )
    {
        projection->code = 6;
        projection->projprms[0] = projection->wgs84_major_axis;
        projection->projprms[1] = projection->wgs84_minor_axis;
        projection->projprms[5] = -71000000.0;
    }
    else
    {
        IAS_LOG_ERROR("Invalid projection read from MAP_PROJECTION in PROJECTION_PARAMETERS group.");
        return(ERROR);
    }
    strcpy( projection->units, "METERS");
    strcpy( projection->datum, "WGS84" );
    projection->spheroid = 12;

    /* Read scene corners */
    if ( ias_odl_get_field( &projection->corners.upleft.x, sizeof(double), IAS_ODL_Double, smeta_odl,
                            "PRODUCT_METADATA", "CORNER_UL_PROJECTION_X_PRODUCT", &count ) != SUCCESS )
    {
        IAS_LOG_ERROR("Reading CORNER_UL_PROJECTION_X_PRODUCT from PRODUCT_METADATA group.");
        return(ERROR);
    }
    if ( ias_odl_get_field( &projection->corners.upleft.y, sizeof(double), IAS_ODL_Double, smeta_odl,
                            "PRODUCT_METADATA", "CORNER_UL_PROJECTION_Y_PRODUCT", &count ) != SUCCESS )
    {
        IAS_LOG_ERROR("Reading CORNER_UL_PROJECTION_Y_PRODUCT from PRODUCT_METADATA group.");
        return(ERROR);
    }
    if ( ias_odl_get_field( &projection->corners.upright.x, sizeof(double), IAS_ODL_Double, smeta_odl,
                            "PRODUCT_METADATA", "CORNER_UR_PROJECTION_X_PRODUCT", &count ) != SUCCESS )
    {
        IAS_LOG_ERROR("Reading CORNER_UR_PROJECTION_X_PRODUCT from PRODUCT_METADATA group.");
        return(ERROR);
    }
    if ( ias_odl_get_field( &projection->corners.upright.y, sizeof(double), IAS_ODL_Double, smeta_odl,
                            "PRODUCT_METADATA", "CORNER_UR_PROJECTION_Y_PRODUCT", &count ) != SUCCESS )
    {
        IAS_LOG_ERROR("Reading CORNER_UR_PROJECTION_Y_PRODUCT from PRODUCT_METADATA group.");
        return(ERROR);
    }
    if ( ias_odl_get_field( &projection->corners.loleft.x, sizeof(double), IAS_ODL_Double, smeta_odl,
                            "PRODUCT_METADATA", "CORNER_LL_PROJECTION_X_PRODUCT", &count ) != SUCCESS )
    {
        IAS_LOG_ERROR("Reading CORNER_LL_PROJECTION_X_PRODUCT from PRODUCT_METADATA group.");
        return(ERROR);
    }
    if ( ias_odl_get_field( &projection->corners.loleft.y, sizeof(double), IAS_ODL_Double, smeta_odl,
                            "PRODUCT_METADATA", "CORNER_LL_PROJECTION_Y_PRODUCT", &count ) != SUCCESS )
    {
        IAS_LOG_ERROR("Reading CORNER_LL_PROJECTION_Y_PRODUCT from PRODUCT_METADATA group.");
        return(ERROR);
    }
    if ( ias_odl_get_field( &projection->corners.loright.x, sizeof(double), IAS_ODL_Double, smeta_odl,
                            "PRODUCT_METADATA", "CORNER_LR_PROJECTION_X_PRODUCT", &count ) != SUCCESS )
    {
        IAS_LOG_ERROR("Reading CORNER_LR_PROJECTION_X_PRODUCT from PRODUCT_METADATA group.");
        return(ERROR);
    }
    if ( ias_odl_get_field( &projection->corners.loright.y, sizeof(double), IAS_ODL_Double, smeta_odl,
                            "PRODUCT_METADATA", "CORNER_LR_PROJECTION_Y_PRODUCT", &count ) != SUCCESS )
    {
        IAS_LOG_ERROR("Reading CORNER_LR_PROJECTION_Y_PRODUCT from PRODUCT_METADATA group.");
        return(ERROR);
    }

    return(SUCCESS);
}

int smeta_read_band_meta(
    SMETA_BAND		*band_smeta,		/* Product metadata structure to load        */
    IAS_OBJ_DESC        *smeta_odl )		/* Product metadata ODL object               */
{
    int		count;				/* Counter for ODL read routines             */

    /* Check the current user band number */
    if ( band_smeta->band == 8 )	/* pan */
    {
        /* Read the number of L1T lines for this band */
        if ( ias_odl_get_field( &band_smeta->l1t_lines, sizeof(int), IAS_ODL_Int, smeta_odl,
                                "PRODUCT_METADATA", "PANCHROMATIC_LINES", &count ) != SUCCESS )
        {
            IAS_LOG_ERROR("Reading PANCHROMATIC_LINES from PRODUCT_METADATA group.");
            return(ERROR);
        }
        /* Read the number of L1T samples for this band */
        if ( ias_odl_get_field( &band_smeta->l1t_samps, sizeof(int), IAS_ODL_Int, smeta_odl,
                                "PRODUCT_METADATA", "PANCHROMATIC_SAMPLES", &count ) != SUCCESS )
        {
            IAS_LOG_ERROR("Reading PANCHROMATIC_SAMPLES from PRODUCT_METADATA group.");
            return(ERROR);
        }
        /* Read the pixel size for this band */
        if ( ias_odl_get_field( &band_smeta->pixsize, sizeof(double), IAS_ODL_Double, smeta_odl,
                                "PROJECTION_PARAMETERS", "GRID_CELL_SIZE_PANCHROMATIC", &count ) != SUCCESS )
        {
            IAS_LOG_ERROR("Reading GRID_CELL_SIZE_PANCHROMATIC from PROJECTION_PARAMETERS group.");
            return(ERROR);
        }
    }
    else if ( band_smeta->band > 9 )  /* thermal */
    {
        /* Read the number of L1T lines for this band */
        if ( ias_odl_get_field( &band_smeta->l1t_lines, sizeof(int), IAS_ODL_Int, smeta_odl,
                                "PRODUCT_METADATA", "THERMAL_LINES", &count ) != SUCCESS )
        {
            IAS_LOG_ERROR("Reading THERMAL_LINES from PRODUCT_METADATA group.");
            return(ERROR);
        }
        /* Read the number of L1T samples for this band */
        if ( ias_odl_get_field( &band_smeta->l1t_samps, sizeof(int), IAS_ODL_Int, smeta_odl,
                                "PRODUCT_METADATA", "THERMAL_SAMPLES", &count ) != SUCCESS )
        {
            IAS_LOG_ERROR("Reading THERMAL_SAMPLES from PRODUCT_METADATA group.");
            return(ERROR);
        }
        /* Read the pixel size for this band */
        if ( ias_odl_get_field( &band_smeta->pixsize, sizeof(double), IAS_ODL_Double, smeta_odl,
                                "PROJECTION_PARAMETERS", "GRID_CELL_SIZE_THERMAL", &count ) != SUCCESS )
        {
            IAS_LOG_ERROR("Reading GRID_CELL_SIZE_THERMAL from PROJECTION_PARAMETERS group.");
            return(ERROR);
        }
    }
    else
    {
        /* Read the number of L1T lines for this band */
        if ( ias_odl_get_field( &band_smeta->l1t_lines, sizeof(int), IAS_ODL_Int, smeta_odl,
                                "PRODUCT_METADATA", "REFLECTIVE_LINES", &count ) != SUCCESS )
        {
            IAS_LOG_ERROR("Reading REFLECTIVE_LINES from PRODUCT_METADATA group.");
            return(ERROR);
        }
        /* Read the number of L1T samples for this band */
        if ( ias_odl_get_field( &band_smeta->l1t_samps, sizeof(int), IAS_ODL_Int, smeta_odl,
                                "PRODUCT_METADATA", "REFLECTIVE_SAMPLES", &count ) != SUCCESS )
        {
            IAS_LOG_ERROR("Reading REFLECTIVE_SAMPLES from PRODUCT_METADATA group.");
            return(ERROR);
        }
        /* Read the pixel size for this band */
        if ( ias_odl_get_field( &band_smeta->pixsize, sizeof(double), IAS_ODL_Double, smeta_odl,
                                "PROJECTION_PARAMETERS", "GRID_CELL_SIZE_REFLECTIVE", &count ) != SUCCESS )
        {
            IAS_LOG_ERROR("Reading GRID_CELL_SIZE_REFLECTIVE from PROJECTION_PARAMETERS group.");
            return(ERROR);
        }
    } 

    return(SUCCESS);
}

int smeta_read_band_meta_ls(
    SMETA_BAND_LS		*band_smeta,		/* Product metadata structure to load        */
    IAS_OBJ_DESC        *smeta_odl )		/* Product metadata ODL object               */
{
    int		count;				/* Counter for ODL read routines             */

    /* Check the current user band number */
    if ( band_smeta->band == 8 )	/* pan */
    {
        /* Read the number of L1T lines for this band */
        if ( ias_odl_get_field( &band_smeta->l1t_lines, sizeof(int), IAS_ODL_Int, smeta_odl,
                                "PRODUCT_METADATA", "PANCHROMATIC_LINES", &count ) != SUCCESS )
        {
            IAS_LOG_ERROR("Reading PANCHROMATIC_LINES from PRODUCT_METADATA group.");
            return(ERROR);
        }
        /* Read the number of L1T samples for this band */
        if ( ias_odl_get_field( &band_smeta->l1t_samps, sizeof(int), IAS_ODL_Int, smeta_odl,
                                "PRODUCT_METADATA", "PANCHROMATIC_SAMPLES", &count ) != SUCCESS )
        {
            IAS_LOG_ERROR("Reading PANCHROMATIC_SAMPLES from PRODUCT_METADATA group.");
            return(ERROR);
        }
        /* Read the pixel size for this band */
        if ( ias_odl_get_field( &band_smeta->pixsize, sizeof(double), IAS_ODL_Double, smeta_odl,
                                "PROJECTION_PARAMETERS", "GRID_CELL_SIZE_PANCHROMATIC", &count ) != SUCCESS )
        {
            IAS_LOG_ERROR("Reading GRID_CELL_SIZE_PANCHROMATIC from PROJECTION_PARAMETERS group.");
            return(ERROR);
        }
    }
    else if ( band_smeta->band == 6 )  /* thermal */
    {
        /* Read the number of L1T lines for this band */
        if ( ias_odl_get_field( &band_smeta->l1t_lines, sizeof(int), IAS_ODL_Int, smeta_odl,
                                "PRODUCT_METADATA", "THERMAL_LINES", &count ) != SUCCESS )
        {
            IAS_LOG_ERROR("Reading THERMAL_LINES from PRODUCT_METADATA group.");
            return(ERROR);
        }
        /* Read the number of L1T samples for this band */
        if ( ias_odl_get_field( &band_smeta->l1t_samps, sizeof(int), IAS_ODL_Int, smeta_odl,
                                "PRODUCT_METADATA", "THERMAL_SAMPLES", &count ) != SUCCESS )
        {
            IAS_LOG_ERROR("Reading THERMAL_SAMPLES from PRODUCT_METADATA group.");
            return(ERROR);
        }
        /* Read the pixel size for this band */
        if ( ias_odl_get_field( &band_smeta->pixsize, sizeof(double), IAS_ODL_Double, smeta_odl,
                                "PROJECTION_PARAMETERS", "GRID_CELL_SIZE_THERMAL", &count ) != SUCCESS )
        {
            IAS_LOG_ERROR("Reading GRID_CELL_SIZE_THERMAL from PROJECTION_PARAMETERS group.");
            return(ERROR);
        }
    }
    else
    {
        /* Read the number of L1T lines for this band */
        if ( ias_odl_get_field( &band_smeta->l1t_lines, sizeof(int), IAS_ODL_Int, smeta_odl,
                                "PRODUCT_METADATA", "REFLECTIVE_LINES", &count ) != SUCCESS )
        {
            IAS_LOG_ERROR("Reading REFLECTIVE_LINES from PRODUCT_METADATA group.");
            return(ERROR);
        }
        /* Read the number of L1T samples for this band */
        if ( ias_odl_get_field( &band_smeta->l1t_samps, sizeof(int), IAS_ODL_Int, smeta_odl,
                                "PRODUCT_METADATA", "REFLECTIVE_SAMPLES", &count ) != SUCCESS )
        {
            IAS_LOG_ERROR("Reading REFLECTIVE_SAMPLES from PRODUCT_METADATA group.");
            return(ERROR);
        }
        /* Read the pixel size for this band */
        if ( ias_odl_get_field( &band_smeta->pixsize, sizeof(double), IAS_ODL_Double, smeta_odl,
                                "PROJECTION_PARAMETERS", "GRID_CELL_SIZE_REFLECTIVE", &count ) != SUCCESS )
        {
            IAS_LOG_ERROR("Reading GRID_CELL_SIZE_REFLECTIVE from PROJECTION_PARAMETERS group.");
            return(ERROR);
        }
    }

    return(SUCCESS);
}

int smeta_load_band_model(
    SMETA_BAND		*band_smeta )		/* Product metadata structure to load        */
{
    /* Set defaults based upon OLI */
    band_smeta->nsca = 14;
    band_smeta->align[0][0] =  0.999997951;
    band_smeta->align[0][1] = -0.000530673;
    band_smeta->align[0][2] = -0.001953614;
    band_smeta->align[1][0] =  0.000527690;
    band_smeta->align[1][1] =  0.999998695;
    band_smeta->align[1][2] = -0.001527061;
    band_smeta->align[2][0] =  0.001954422;
    band_smeta->align[2][1] =  0.001526027;
    band_smeta->align[2][2] =  0.999996925;

    /* Switch on the current user band number */
    switch ( band_smeta->band )
    {
        case 1:
            /* Sudipta new addition for OLI to extract SCA and Det numbers */
            band_smeta->num_detectors = 494;
            /* End Sudipta new addition for OLI */
            band_smeta->legendre[0][0][0] = 6.700457E-03;	band_smeta->legendre[0][0][1] = -3.401961E-04;  band_smeta->legendre[0][0][2] = 3.020421E-06;	band_smeta->legendre[0][0][3] = 0.000000E+00;	/* Band 01  SCA 01  X */
            band_smeta->legendre[0][1][0] = 1.247760E-01;	band_smeta->legendre[0][1][1] = -1.022901E-02;	band_smeta->legendre[0][1][2] = 1.129022E-05;	band_smeta->legendre[0][1][3] = 0.000000E+00;	/* Band 01  SCA 01  Y */
            band_smeta->legendre[1][0][0] = -5.513364E-03;	band_smeta->legendre[1][0][1] = -2.558301E-04;	band_smeta->legendre[1][0][2] = 2.493720E-06;	band_smeta->legendre[1][0][3] = 0.000000E+00;	/* Band 01  SCA 02  X */
            band_smeta->legendre[1][1][0] = 1.054260E-01;	band_smeta->legendre[1][1][1] = -1.014920E-02;	band_smeta->legendre[1][1][2] = 9.369339E-06;	band_smeta->legendre[1][1][3] = 0.000000E+00;	/* Band 01  SCA 02  Y */
            band_smeta->legendre[2][0][0] = 6.323671E-03;	band_smeta->legendre[2][0][1] = -2.358493E-04;	band_smeta->legendre[2][0][2] = 2.698207E-06;	band_smeta->legendre[2][0][3] = 0.000000E+00;	/* Band 01  SCA 03  X */
            band_smeta->legendre[2][1][0] = 8.611552E-02;	band_smeta->legendre[2][1][1] = -1.012057E-02;	band_smeta->legendre[2][1][2] = 8.258542E-06;	band_smeta->legendre[2][1][3] = 0.000000E+00;	/* Band 01  SCA 03  Y */
            band_smeta->legendre[3][0][0] = -5.784523E-03;	band_smeta->legendre[3][0][1] = -1.612340E-04;	band_smeta->legendre[3][0][2] = 2.520839E-06;	band_smeta->legendre[3][0][3] = 0.000000E+00;	/* Band 01  SCA 04  X */
            band_smeta->legendre[3][1][0] = 6.694656E-02;	band_smeta->legendre[3][1][1] = -1.006099E-02;	band_smeta->legendre[3][1][2] = 6.206345E-06;	band_smeta->legendre[3][1][3] = 0.000000E+00;	/* Band 01  SCA 04  Y */
            band_smeta->legendre[4][0][0] = 6.078253E-03;	band_smeta->legendre[4][0][1] = -1.311456E-04;	band_smeta->legendre[4][0][2] = 3.930979E-06;	band_smeta->legendre[4][0][3] = 0.000000E+00;	/* Band 01  SCA 05  X */
            band_smeta->legendre[4][1][0] = 4.779359E-02;	band_smeta->legendre[4][1][1] = -1.004966E-02;	band_smeta->legendre[4][1][2] = 5.199712E-06;	band_smeta->legendre[4][1][3] = 0.000000E+00;	/* Band 01  SCA 05  Y */
            band_smeta->legendre[5][0][0] = -5.924803E-03;	band_smeta->legendre[5][0][1] = -7.073287E-05;	band_smeta->legendre[5][0][2] = 2.868175E-06;	band_smeta->legendre[5][0][3] = 0.000000E+00;	/* Band 01  SCA 06  X */
            band_smeta->legendre[5][1][0] = 2.872972E-02;	band_smeta->legendre[5][1][1] = -1.001174E-02;	band_smeta->legendre[5][1][2] = 2.787794E-06;	band_smeta->legendre[5][1][3] = 0.000000E+00;	/* Band 01  SCA 06  Y */
            band_smeta->legendre[6][0][0] = 5.971097E-03;	band_smeta->legendre[6][0][1] = -2.815200E-05;	band_smeta->legendre[6][0][2] = 3.190979E-06;	band_smeta->legendre[6][0][3] = 0.000000E+00;	/* Band 01  SCA 07  X */
            band_smeta->legendre[6][1][0] = 9.658241E-03;	band_smeta->legendre[6][1][1] = -1.002124E-02;	band_smeta->legendre[6][1][2] = 1.087904E-06;	band_smeta->legendre[6][1][3] = 0.000000E+00;	/* Band 01  SCA 07  Y */
            band_smeta->legendre[7][0][0] = -5.966687E-03;	band_smeta->legendre[7][0][1] = 2.091761E-05;	band_smeta->legendre[7][0][2] = 2.181517E-06;	band_smeta->legendre[7][0][3] = 0.000000E+00;	/* Band 01  SCA 08  X */
            band_smeta->legendre[7][1][0] = -9.381294E-03;	band_smeta->legendre[7][1][1] = -1.000203E-02;	band_smeta->legendre[7][1][2] = -1.944770E-06;	band_smeta->legendre[7][1][3] = 0.000000E+00;	/* Band 01  SCA 08  Y */
            band_smeta->legendre[8][0][0] = 6.006426E-03;	band_smeta->legendre[8][0][1] = 7.643835E-05;	band_smeta->legendre[8][0][2] = 3.298299E-06;	band_smeta->legendre[8][0][3] = 0.000000E+00;	/* Band 01  SCA 09  X */
            band_smeta->legendre[8][1][0] = -2.843993E-02;	band_smeta->legendre[8][1][1] = -1.003132E-02;	band_smeta->legendre[8][1][2] = -2.784321E-06;	band_smeta->legendre[8][1][3] = 0.000000E+00;	/* Band 01  SCA 09  Y */
            band_smeta->legendre[9][0][0] = -5.884010E-03;	band_smeta->legendre[9][0][1] = 1.143512E-04;	band_smeta->legendre[9][0][2] = 3.354213E-06;	band_smeta->legendre[9][0][3] = 0.000000E+00;	/* Band 01  SCA 10  X */
            band_smeta->legendre[9][1][0] = -4.752226E-02;	band_smeta->legendre[9][1][1] = -1.003170E-02;	band_smeta->legendre[9][1][2] = -4.403675E-06;	band_smeta->legendre[9][1][3] = 0.000000E+00;	/* Band 01  SCA 10  Y */
            band_smeta->legendre[10][0][0] = 6.170485E-03;	band_smeta->legendre[10][0][1] = 1.818443E-04;	band_smeta->legendre[10][0][2] = 3.255665E-06;	band_smeta->legendre[10][0][3] = 0.000000E+00;	/* Band 01  SCA 11  X */
            band_smeta->legendre[10][1][0] = -6.664497E-02;	band_smeta->legendre[10][1][1] = -1.007982E-02;	band_smeta->legendre[10][1][2] = -6.278005E-06;	band_smeta->legendre[10][1][3] = 0.000000E+00;	/* Band 01  SCA 11  Y */
            band_smeta->legendre[11][0][0] = -5.686986E-03;	band_smeta->legendre[11][0][1] = 2.051895E-04;	band_smeta->legendre[11][0][2] = 2.350731E-06;	band_smeta->legendre[11][0][3] = 0.000000E+00;	/* Band 01  SCA 12  X */
            band_smeta->legendre[11][1][0] = -8.585954E-02;	band_smeta->legendre[11][1][1] = -1.009955E-02;	band_smeta->legendre[11][1][2] = -6.930943E-06;	band_smeta->legendre[11][1][3] = 0.000000E+00;	/* Band 01  SCA 12  Y */
            band_smeta->legendre[12][0][0] = 6.476124E-03;	band_smeta->legendre[12][0][1] = 2.880301E-04;	band_smeta->legendre[12][0][2] = 4.495383E-06;	band_smeta->legendre[12][0][3] = 0.000000E+00;	/* Band 01  SCA 13  X */
            band_smeta->legendre[12][1][0] = -1.051198E-01;	band_smeta->legendre[12][1][1] = -1.016743E-02;	band_smeta->legendre[12][1][2] = -1.114517E-05;	band_smeta->legendre[12][1][3] = 0.000000E+00;	/* Band 01  SCA 13  Y */
            band_smeta->legendre[13][0][0] = -5.351748E-03;	band_smeta->legendre[13][0][1] = 2.992144E-04;	band_smeta->legendre[13][0][2] = 3.867663E-06;	band_smeta->legendre[13][0][3] = 0.000000E+00;	/* Band 01  SCA 14  X */
            band_smeta->legendre[13][1][0] = -1.245202E-01;	band_smeta->legendre[13][1][1] = -1.020712E-02;	band_smeta->legendre[13][1][2] = -1.109152E-05;	band_smeta->legendre[13][1][3] = 0.000000E+00;	/* Band 01  SCA 14  Y */
            break;
        case 2:
            /* Sudipta new addition for OLI to extract SCA and Det numbers */
            band_smeta->num_detectors = 494;
            /* End Sudipta new addition for OLI */
            band_smeta->legendre[0][0][0] = 5.465425E-03;	band_smeta->legendre[0][0][1] = -3.383192E-04;	band_smeta->legendre[0][0][2] = 3.087230E-06;	band_smeta->legendre[0][0][3] = 0.000000E+00;	/* Band 02  SCA 01  X */
            band_smeta->legendre[0][1][0] = 1.247768E-01;	band_smeta->legendre[0][1][1] = -1.022709E-02;	band_smeta->legendre[0][1][2] = 1.132283E-05;	band_smeta->legendre[0][1][3] = 0.000000E+00;	/* Band 02  SCA 01  Y */
            band_smeta->legendre[1][0][0] = -4.283082E-03;	band_smeta->legendre[1][0][1] = -2.570051E-04;	band_smeta->legendre[1][0][2] = 2.581862E-06;	band_smeta->legendre[1][0][3] = 0.000000E+00;	/* Band 02  SCA 02  X */
            band_smeta->legendre[1][1][0] = 1.054274E-01;	band_smeta->legendre[1][1][1] = -1.015115E-02;	band_smeta->legendre[1][1][2] = 9.453706E-06;	band_smeta->legendre[1][1][3] = 0.000000E+00;	/* Band 02  SCA 02  Y */
            band_smeta->legendre[2][0][0] = 5.092865E-03;	band_smeta->legendre[2][0][1] = -2.346027E-04;	band_smeta->legendre[2][0][2] = 2.631629E-06;	band_smeta->legendre[2][0][3] = 0.000000E+00;	/* Band 02  SCA 03  X */
            band_smeta->legendre[2][1][0] = 8.611595E-02;	band_smeta->legendre[2][1][1] = -1.011873E-02;	band_smeta->legendre[2][1][2] = 8.174708E-06;	band_smeta->legendre[2][1][3] = 0.000000E+00;	/* Band 02  SCA 03  Y */
            band_smeta->legendre[3][0][0] = -4.558100E-03;	band_smeta->legendre[3][0][1] = -1.621403E-04;	band_smeta->legendre[3][0][2] = 2.460853E-06;	band_smeta->legendre[3][0][3] = 0.000000E+00;	/* Band 02  SCA 04  X */
            band_smeta->legendre[3][1][0] = 6.694782E-02;	band_smeta->legendre[3][1][1] = -1.006298E-02;	band_smeta->legendre[3][1][2] = 6.285042E-06;	band_smeta->legendre[3][1][3] = 0.000000E+00;	/* Band 02  SCA 04  Y */
            band_smeta->legendre[4][0][0] = 4.850894E-03;	band_smeta->legendre[4][0][1] = -1.301959E-04;	band_smeta->legendre[4][0][2] = 3.883217E-06;	band_smeta->legendre[4][0][3] = 0.000000E+00;	/* Band 02  SCA 05  X */
            band_smeta->legendre[4][1][0] = 4.779369E-02;	band_smeta->legendre[4][1][1] = -1.004771E-02;	band_smeta->legendre[4][1][2] = 5.218173E-06;	band_smeta->legendre[4][1][3] = 0.000000E+00;	/* Band 02  SCA 05  Y */
            band_smeta->legendre[5][0][0] = -4.700814E-03;	band_smeta->legendre[5][0][1] = -7.089173E-05;	band_smeta->legendre[5][0][2] = 3.002382E-06;	band_smeta->legendre[5][0][3] = 0.000000E+00;	/* Band 02  SCA 06  X */
            band_smeta->legendre[5][1][0] = 2.873005E-02;	band_smeta->legendre[5][1][1] = -1.001389E-02;	band_smeta->legendre[5][1][2] = 2.839258E-06;	band_smeta->legendre[5][1][3] = 0.000000E+00;	/* Band 02  SCA 06  Y */
            band_smeta->legendre[6][0][0] = 4.745216E-03;	band_smeta->legendre[6][0][1] = -2.763869E-05;	band_smeta->legendre[6][0][2] = 3.292341E-06;	band_smeta->legendre[6][0][3] = 0.000000E+00;	/* Band 02  SCA 07  X */
            band_smeta->legendre[6][1][0] = 9.658213E-03;	band_smeta->legendre[6][1][1] = -1.001938E-02;	band_smeta->legendre[6][1][2] = 9.347606E-07;	band_smeta->legendre[6][1][3] = 0.000000E+00;	/* Band 02  SCA 07  Y */
            band_smeta->legendre[7][0][0] = -4.743515E-03;	band_smeta->legendre[7][0][1] = 2.140725E-05;	band_smeta->legendre[7][0][2] = 2.208777E-06;	band_smeta->legendre[7][0][3] = 0.000000E+00;	/* Band 02  SCA 08  X */
            band_smeta->legendre[7][1][0] = -9.381283E-03;	band_smeta->legendre[7][1][1] = -1.000392E-02;	band_smeta->legendre[7][1][2] = -2.009904E-06;	band_smeta->legendre[7][1][3] = 0.000000E+00;	/* Band 02  SCA 08  Y */
            band_smeta->legendre[8][0][0] = 4.779561E-03;	band_smeta->legendre[8][0][1] = 7.629733E-05;	band_smeta->legendre[8][0][2] = 3.299964E-06;	band_smeta->legendre[8][0][3] = 0.000000E+00;	/* Band 02  SCA 09  X */
            band_smeta->legendre[8][1][0] = -2.844043E-02;	band_smeta->legendre[8][1][1] = -1.002930E-02;	band_smeta->legendre[8][1][2] = -2.795610E-06;	band_smeta->legendre[8][1][3] = 0.000000E+00;	/* Band 02  SCA 09  Y */
            band_smeta->legendre[9][0][0] = -4.658966E-03;	band_smeta->legendre[9][0][1] = 1.150612E-04;	band_smeta->legendre[9][0][2] = 3.388692E-06;	band_smeta->legendre[9][0][3] = 0.000000E+00;	/* Band 02  SCA 10  X */
            band_smeta->legendre[9][1][0] = -4.752238E-02;	band_smeta->legendre[9][1][1] = -1.003369E-02;	band_smeta->legendre[9][1][2] = -4.345525E-06;	band_smeta->legendre[9][1][3] = 0.000000E+00;	/* Band 02  SCA 10  Y */
            band_smeta->legendre[10][0][0] = 4.941977E-03;	band_smeta->legendre[10][0][1] = 1.813334E-04;	band_smeta->legendre[10][0][2] = 3.257583E-06;	band_smeta->legendre[10][0][3] = 0.000000E+00;	/* Band 02  SCA 11  X */
            band_smeta->legendre[10][1][0] = -6.664576E-02;	band_smeta->legendre[10][1][1] = -1.007792E-02;	band_smeta->legendre[10][1][2] = -6.299673E-06;	band_smeta->legendre[10][1][3] = 0.000000E+00;	/* Band 02  SCA 11  Y */
            band_smeta->legendre[11][0][0] = -4.458698E-03;	band_smeta->legendre[11][0][1] = 2.065198E-04;	band_smeta->legendre[11][0][2] = 2.463545E-06;	band_smeta->legendre[11][0][3] = 0.000000E+00;	/* Band 02  SCA 12  X */
            band_smeta->legendre[11][1][0] = -8.586029E-02;	band_smeta->legendre[11][1][1] = -1.010161E-02;	band_smeta->legendre[11][1][2] = -6.999770E-06;	band_smeta->legendre[11][1][3] = 0.000000E+00;	/* Band 02  SCA 12  Y */
            band_smeta->legendre[12][0][0] = 5.243743E-03;	band_smeta->legendre[12][0][1] = 2.868757E-04;	band_smeta->legendre[12][0][2] = 4.569801E-06;	band_smeta->legendre[12][0][3] = 0.000000E+00;	/* Band 02  SCA 13  X */
            band_smeta->legendre[12][1][0] = -1.051210E-01;	band_smeta->legendre[12][1][1] = -1.016548E-02;	band_smeta->legendre[12][1][2] = -1.108402E-05;	band_smeta->legendre[12][1][3] = 0.000000E+00;	/* Band 02  SCA 13  Y */
            band_smeta->legendre[13][0][0] = -4.119881E-03;	band_smeta->legendre[13][0][1] = 3.013370E-04;	band_smeta->legendre[13][0][2] = 3.925234E-06;	band_smeta->legendre[13][0][3] = 0.000000E+00;	/* Band 02  SCA 14  X */
            band_smeta->legendre[13][1][0] = -1.245216E-01;	band_smeta->legendre[13][1][1] = -1.020916E-02;	band_smeta->legendre[13][1][2] = -1.096852E-05;	band_smeta->legendre[13][1][3] = 0.000000E+00;	/* Band 02  SCA 14  Y */
            break;
        case 3:
            /* Sudipta new addition for OLI to extract SCA and Det numbers */
            band_smeta->num_detectors = 494;
            /* End Sudipta new addition for OLI */
            band_smeta->legendre[0][0][0] = 1.041906E-02;	band_smeta->legendre[0][0][1] = -3.454704E-04;	band_smeta->legendre[0][0][2] = 3.539931E-06;	band_smeta->legendre[0][0][3] = 0.000000E+00;	/* Band 03  SCA 01  X */
            band_smeta->legendre[0][1][0] = 1.247782E-01;	band_smeta->legendre[0][1][1] = -1.023510E-02;	band_smeta->legendre[0][1][2] = 1.118006E-05;	band_smeta->legendre[0][1][3] = 0.000000E+00;	/* Band 03  SCA 01  Y */
            band_smeta->legendre[1][0][0] = -9.193152E-03;	band_smeta->legendre[1][0][1] = -2.515110E-04;	band_smeta->legendre[1][0][2] = 2.328476E-06;	band_smeta->legendre[1][0][3] = 0.000000E+00;	/* Band 03  SCA 02  X */
            band_smeta->legendre[1][1][0] = 1.054261E-01;	band_smeta->legendre[1][1][1] = -1.014363E-02;	band_smeta->legendre[1][1][2] = 9.462277E-06;	band_smeta->legendre[1][1][3] = 0.000000E+00;	/* Band 03  SCA 02  Y */
            band_smeta->legendre[2][0][0] = 1.002762E-02;	band_smeta->legendre[2][0][1] = -2.394232E-04;	band_smeta->legendre[2][0][2] = 2.684126E-06;	band_smeta->legendre[2][0][3] = 0.000000E+00;	/* Band 03  SCA 03  X */
            band_smeta->legendre[2][1][0] = 8.611718E-02;	band_smeta->legendre[2][1][1] = -1.012686E-02;	band_smeta->legendre[2][1][2] = 8.323528E-06;	band_smeta->legendre[2][1][3] = 0.000000E+00;	/* Band 03  SCA 03  Y */
            band_smeta->legendre[3][0][0] = -9.452204E-03;	band_smeta->legendre[3][0][1] = -1.587866E-04;	band_smeta->legendre[3][0][2] = 2.513854E-06;	band_smeta->legendre[3][0][3] = 0.000000E+00;	/* Band 03  SCA 04  X */
            band_smeta->legendre[3][1][0] = 6.694558E-02;	band_smeta->legendre[3][1][1] = -1.005562E-02;	band_smeta->legendre[3][1][2] = 6.345248E-06;	band_smeta->legendre[3][1][3] = 0.000000E+00;	/* Band 03  SCA 04  Y */
            band_smeta->legendre[4][0][0] = 9.773615E-03;	band_smeta->legendre[4][0][1] = -1.328606E-04;	band_smeta->legendre[4][0][2] = 3.930089E-06;	band_smeta->legendre[4][0][3] = 0.000000E+00;	/* Band 03  SCA 05  X */
            band_smeta->legendre[4][1][0] = 4.779474E-02;	band_smeta->legendre[4][1][1] = -1.005598E-02;	band_smeta->legendre[4][1][2] = 5.093887E-06;	band_smeta->legendre[4][1][3] = 0.000000E+00;	/* Band 03  SCA 05  Y */
            band_smeta->legendre[5][0][0] = -9.586577E-03;	band_smeta->legendre[5][0][1] = -6.942392E-05;	band_smeta->legendre[5][0][2] = 2.734550E-06;	band_smeta->legendre[5][0][3] = 0.000000E+00;	/* Band 03  SCA 06  X */
            band_smeta->legendre[5][1][0] = 2.872934E-02;	band_smeta->legendre[5][1][1] = -1.000625E-02;	band_smeta->legendre[5][1][2] = 2.671157E-06;	band_smeta->legendre[5][1][3] = 0.000000E+00;	/* Band 03  SCA 06  Y */
            band_smeta->legendre[6][0][0] = 9.663069E-03;	band_smeta->legendre[6][0][1] = -2.837736E-05;	band_smeta->legendre[6][0][2] = 3.214780E-06;	band_smeta->legendre[6][0][3] = 0.000000E+00;	/* Band 03  SCA 07  X */
            band_smeta->legendre[6][1][0] = 9.658657E-03;	band_smeta->legendre[6][1][1] = -1.002772E-02;	band_smeta->legendre[6][1][2] = 1.041097E-06;	band_smeta->legendre[6][1][3] = 0.000000E+00;	/* Band 03  SCA 07  Y */
            band_smeta->legendre[7][0][0] = -9.626794E-03;	band_smeta->legendre[7][0][1] = 2.058298E-05;	band_smeta->legendre[7][0][2] = 2.040849E-06;	band_smeta->legendre[7][0][3] = 0.000000E+00;	/* Band 03  SCA 08  X */
            band_smeta->legendre[7][1][0] = -9.381404E-03;	band_smeta->legendre[7][1][1] = -9.997013E-03;	band_smeta->legendre[7][1][2] = -1.657774E-06;	band_smeta->legendre[7][1][3] = 0.000000E+00;	/* Band 03  SCA 08  Y */
            band_smeta->legendre[8][0][0] = 9.699190E-03;	band_smeta->legendre[8][0][1] = 7.755539E-05;	band_smeta->legendre[8][0][2] = 3.520416E-06;	band_smeta->legendre[8][0][3] = 0.000000E+00;	/* Band 03  SCA 09  X */
            band_smeta->legendre[8][1][0] = -2.843975E-02;	band_smeta->legendre[8][1][1] = -1.003745E-02;	band_smeta->legendre[8][1][2] = -2.736407E-06;	band_smeta->legendre[8][1][3] = 0.000000E+00;	/* Band 03  SCA 09  Y */
            band_smeta->legendre[9][0][0] = -9.548452E-03;	band_smeta->legendre[9][0][1] = 1.123876E-04;	band_smeta->legendre[9][0][2] = 3.198573E-06;	band_smeta->legendre[9][0][3] = 0.000000E+00;	/* Band 03  SCA 10  X */
            band_smeta->legendre[9][1][0] = -4.752309E-02;	band_smeta->legendre[9][1][1] = -1.002628E-02;	band_smeta->legendre[9][1][2] = -4.235382E-06;	band_smeta->legendre[9][1][3] = 0.000000E+00;	/* Band 03  SCA 10  Y */
            band_smeta->legendre[10][0][0] = 9.869869E-03;	band_smeta->legendre[10][0][1] = 1.847020E-04;	band_smeta->legendre[10][0][2] = 3.332958E-06;	band_smeta->legendre[10][0][3] = 0.000000E+00;	/* Band 03  SCA 11  X */
            band_smeta->legendre[10][1][0] = -6.664501E-02;	band_smeta->legendre[10][1][1] = -1.008613E-02;	band_smeta->legendre[10][1][2] = -6.192518E-06;	band_smeta->legendre[10][1][3] = 0.000000E+00;	/* Band 03  SCA 11  Y */
            band_smeta->legendre[11][0][0] = -9.360033E-03;	band_smeta->legendre[11][0][1] = 2.019728E-04;	band_smeta->legendre[11][0][2] = 2.378572E-06;	band_smeta->legendre[11][0][3] = 0.000000E+00;	/* Band 03  SCA 12  X */
            band_smeta->legendre[11][1][0] = -8.586034E-02;	band_smeta->legendre[11][1][1] = -1.009405E-02;	band_smeta->legendre[11][1][2] = -7.055363E-06;	band_smeta->legendre[11][1][3] = 0.000000E+00;	/* Band 03  SCA 12  Y */
            band_smeta->legendre[12][0][0] = 1.018724E-02;	band_smeta->legendre[12][0][1] = 2.922704E-04;	band_smeta->legendre[12][0][2] = 4.712555E-06;	band_smeta->legendre[12][0][3] = 0.000000E+00;	/* Band 03  SCA 13  X */
            band_smeta->legendre[12][1][0] = -1.051198E-01;	band_smeta->legendre[12][1][1] = -1.017391E-02;	band_smeta->legendre[12][1][2] = -1.079104E-05;	band_smeta->legendre[12][1][3] = 0.000000E+00;	/* Band 03  SCA 13  Y */
            band_smeta->legendre[13][0][0] = -9.039467E-03;	band_smeta->legendre[13][0][1] = 2.943692E-04;	band_smeta->legendre[13][0][2] = 3.845812E-06;	band_smeta->legendre[13][0][3] = 0.000000E+00;	/* Band 03  SCA 14  X */
            band_smeta->legendre[13][1][0] = -1.245210E-01;	band_smeta->legendre[13][1][1] = -1.020184E-02;	band_smeta->legendre[13][1][2] = -1.093841E-05;	band_smeta->legendre[13][1][3] = 0.000000E+00;	/* Band 03  SCA 14  Y */
            break;
        case 4:
            /* Sudipta new addition for OLI to extract SCA and Det numbers */
            band_smeta->num_detectors = 494;
            /* End Sudipta new addition for OLI */
            band_smeta->legendre[0][0][0] = 9.181792E-03;	band_smeta->legendre[0][0][1] = -3.437803E-04;	band_smeta->legendre[0][0][2] = 3.514507E-06;	band_smeta->legendre[0][0][3] = 0.000000E+00;	/* Band 04  SCA 01  X */
            band_smeta->legendre[0][1][0] = 1.247782E-01;	band_smeta->legendre[0][1][1] = -1.023295E-02;	band_smeta->legendre[0][1][2] = 1.115630E-05;	band_smeta->legendre[0][1][3] = 0.000000E+00;	/* Band 04  SCA 01  Y */
            band_smeta->legendre[1][0][0] = -7.964812E-03;	band_smeta->legendre[1][0][1] = -2.526059E-04;	band_smeta->legendre[1][0][2] = 2.288381E-06;	band_smeta->legendre[1][0][3] = 0.000000E+00;	/* Band 04  SCA 02  X */
            band_smeta->legendre[1][1][0] = 1.054266E-01;	band_smeta->legendre[1][1][1] = -1.014554E-02;	band_smeta->legendre[1][1][2] = 9.445541E-06;	band_smeta->legendre[1][1][3] = 0.000000E+00;	/* Band 04  SCA 02  Y */
            band_smeta->legendre[2][0][0] = 8.795319E-03;	band_smeta->legendre[2][0][1] = -2.381021E-04;	band_smeta->legendre[2][0][2] = 2.517772E-06;	band_smeta->legendre[2][0][3] = 0.000000E+00;	/* Band 04  SCA 03  X */
            band_smeta->legendre[2][1][0] = 8.611717E-02;	band_smeta->legendre[2][1][1] = -1.012488E-02;	band_smeta->legendre[2][1][2] = 8.379305E-06;	band_smeta->legendre[2][1][3] = 0.000000E+00;	/* Band 04  SCA 03  Y */
            band_smeta->legendre[3][0][0] = -8.228379E-03;	band_smeta->legendre[3][0][1] = -1.594470E-04;	band_smeta->legendre[3][0][2] = 2.492521E-06;	band_smeta->legendre[3][0][3] = 0.000000E+00;	/* Band 04  SCA 04  X */
            band_smeta->legendre[3][1][0] = 6.694637E-02;	band_smeta->legendre[3][1][1] = -1.005741E-02;	band_smeta->legendre[3][1][2] = 6.281542E-06;	band_smeta->legendre[3][1][3] = 0.000000E+00;	/* Band 04  SCA 04  Y */
            band_smeta->legendre[4][0][0] = 8.544355E-03;	band_smeta->legendre[4][0][1] = -1.320504E-04;	band_smeta->legendre[4][0][2] = 3.817695E-06;	band_smeta->legendre[4][0][3] = 0.000000E+00;	/* Band 04  SCA 05  X */
            band_smeta->legendre[4][1][0] = 4.779462E-02;	band_smeta->legendre[4][1][1] = -1.005398E-02;	band_smeta->legendre[4][1][2] = 5.000550E-06;	band_smeta->legendre[4][1][3] = 0.000000E+00;	/* Band 04  SCA 05  Y */
            band_smeta->legendre[5][0][0] = -8.364217E-03;	band_smeta->legendre[5][0][1] = -6.971393E-05;	band_smeta->legendre[5][0][2] = 2.768567E-06;	band_smeta->legendre[5][0][3] = 0.000000E+00;	/* Band 04  SCA 06  X */
            band_smeta->legendre[5][1][0] = 2.872965E-02;	band_smeta->legendre[5][1][1] = -1.000810E-02;	band_smeta->legendre[5][1][2] = 2.539207E-06;	band_smeta->legendre[5][1][3] = 0.000000E+00;	/* Band 04  SCA 06  Y */
            band_smeta->legendre[6][0][0] = 8.434648E-03;	band_smeta->legendre[6][0][1] = -2.821683E-05;	band_smeta->legendre[6][0][2] = 3.377552E-06;	band_smeta->legendre[6][0][3] = 0.000000E+00;	/* Band 04  SCA 07  X */
            band_smeta->legendre[6][1][0] = 9.658525E-03;	band_smeta->legendre[6][1][1] = -1.002580E-02;	band_smeta->legendre[6][1][2] = 8.874323E-07;	band_smeta->legendre[6][1][3] = 0.000000E+00;	/* Band 04  SCA 07  Y */
            band_smeta->legendre[7][0][0] = -8.405057E-03;	band_smeta->legendre[7][0][1] = 2.086813E-05;	band_smeta->legendre[7][0][2] = 2.009307E-06;	band_smeta->legendre[7][0][3] = 0.000000E+00;	/* Band 04  SCA 08  X */
            band_smeta->legendre[7][1][0] = -9.381472E-03;	band_smeta->legendre[7][1][1] = -9.998813E-03;	band_smeta->legendre[7][1][2] = -1.491295E-06;	band_smeta->legendre[7][1][3] = 0.000000E+00;	/* Band 04  SCA 08  Y */
            band_smeta->legendre[8][0][0] = 8.470769E-03;	band_smeta->legendre[8][0][1] = 7.719387E-05;	band_smeta->legendre[8][0][2] = 3.390413E-06;	band_smeta->legendre[8][0][3] = 0.000000E+00;	/* Band 04  SCA 09  X */
            band_smeta->legendre[8][1][0] = -2.844009E-02;	band_smeta->legendre[8][1][1] = -1.003532E-02;	band_smeta->legendre[8][1][2] = -2.782992E-06;	band_smeta->legendre[8][1][3] = 0.000000E+00;	/* Band 04  SCA 09  Y */
            band_smeta->legendre[9][0][0] = -8.324964E-03;	band_smeta->legendre[9][0][1] = 1.130198E-04;	band_smeta->legendre[9][0][2] = 3.245731E-06;	band_smeta->legendre[9][0][3] = 0.000000E+00;	/* Band 04  SCA 10  X */
            band_smeta->legendre[9][1][0] = -4.752317E-02;	band_smeta->legendre[9][1][1] = -1.002807E-02;	band_smeta->legendre[9][1][2] = -4.149779E-06;	band_smeta->legendre[9][1][3] = 0.000000E+00;	/* Band 04  SCA 10  Y */
            band_smeta->legendre[10][0][0] = 8.639555E-03;	band_smeta->legendre[10][0][1] = 1.841130E-04;	band_smeta->legendre[10][0][2] = 3.334931E-06;	band_smeta->legendre[10][0][3] = 0.000000E+00;	/* Band 04  SCA 11  X */
            band_smeta->legendre[10][1][0] = -6.664536E-02;	band_smeta->legendre[10][1][1] = -1.008416E-02;	band_smeta->legendre[10][1][2] = -6.288042E-06;	band_smeta->legendre[10][1][3] = 0.000000E+00;	/* Band 04  SCA 11  Y */
            band_smeta->legendre[11][0][0] = -8.133795E-03;	band_smeta->legendre[11][0][1] = 2.031498E-04;	band_smeta->legendre[11][0][2] = 2.449548E-06;	band_smeta->legendre[11][0][3] = 0.000000E+00;	/* Band 04  SCA 12  X */
            band_smeta->legendre[11][1][0] = -8.586056E-02;	band_smeta->legendre[11][1][1] = -1.009593E-02;	band_smeta->legendre[11][1][2] = -7.113677E-06;	band_smeta->legendre[11][1][3] = 0.000000E+00;	/* Band 04  SCA 12  Y */
            band_smeta->legendre[12][0][0] = 8.952379E-03;	band_smeta->legendre[12][0][1] = 2.909075E-04;	band_smeta->legendre[12][0][2] = 4.675834E-06;	band_smeta->legendre[12][0][3] = 0.000000E+00;	/* Band 04  SCA 13  X */
            band_smeta->legendre[12][1][0] = -1.051203E-01;	band_smeta->legendre[12][1][1] = -1.017182E-02;	band_smeta->legendre[12][1][2] = -1.086626E-05;	band_smeta->legendre[12][1][3] = 0.000000E+00;	/* Band 04  SCA 13  Y */
            band_smeta->legendre[13][0][0] = -7.808343E-03;	band_smeta->legendre[13][0][1] = 2.961812E-04;	band_smeta->legendre[13][0][2] = 3.975986E-06;	band_smeta->legendre[13][0][3] = 0.000000E+00;	/* Band 04  SCA 14  X */
            band_smeta->legendre[13][1][0] = -1.245214E-01;	band_smeta->legendre[13][1][1] = -1.020366E-02;	band_smeta->legendre[13][1][2] = -1.070862E-05;	band_smeta->legendre[13][1][3] = 0.000000E+00;	/* Band 04  SCA 14  Y */
            break;
        case 5:
            /* Sudipta new addition for OLI to extract SCA and Det numbers */
            band_smeta->num_detectors = 494;
            /* End Sudipta new addition for OLI */
            band_smeta->legendre[0][0][0] = 7.945358E-03;	band_smeta->legendre[0][0][1] = -3.421326E-04;	band_smeta->legendre[0][0][2] = 3.381643E-06;	band_smeta->legendre[0][0][3] = 0.000000E+00;	/* Band 05  SCA 01  X */
            band_smeta->legendre[0][1][0] = 1.247794E-01;	band_smeta->legendre[0][1][1] = -1.023102E-02;	band_smeta->legendre[0][1][2] = 1.116419E-05;	band_smeta->legendre[0][1][3] = 0.000000E+00;	/* Band 05  SCA 01  Y */
            band_smeta->legendre[1][0][0] = -6.733936E-03;	band_smeta->legendre[1][0][1] = -2.540458E-04;	band_smeta->legendre[1][0][2] = 2.394016E-06;	band_smeta->legendre[1][0][3] = 0.000000E+00;	/* Band 05  SCA 02  X */
            band_smeta->legendre[1][1][0] = 1.054282E-01;	band_smeta->legendre[1][1][1] = -1.014777E-02;	band_smeta->legendre[1][1][2] = 9.520113E-06;	band_smeta->legendre[1][1][3] = 0.000000E+00;	/* Band 05  SCA 02  Y */
            band_smeta->legendre[2][0][0] = 7.563138E-03;	band_smeta->legendre[2][0][1] = -2.368287E-04;	band_smeta->legendre[2][0][2] = 2.428350E-06;	band_smeta->legendre[2][0][3] = 0.000000E+00;	/* Band 05  SCA 03  X */
            band_smeta->legendre[2][1][0] = 8.611789E-02;	band_smeta->legendre[2][1][1] = -1.012312E-02;	band_smeta->legendre[2][1][2] = 8.413135E-06;	band_smeta->legendre[2][1][3] = 0.000000E+00;	/* Band 05  SCA 03  Y */
            band_smeta->legendre[3][0][0] = -7.001234E-03;	band_smeta->legendre[3][0][1] = -1.606825E-04;	band_smeta->legendre[3][0][2] = 2.504449E-06;	band_smeta->legendre[3][0][3] = 0.000000E+00;	/* Band 05  SCA 04  X */
            band_smeta->legendre[3][1][0] = 6.694778E-02;	band_smeta->legendre[3][1][1] = -1.005950E-02;	band_smeta->legendre[3][1][2] = 6.469021E-06;	band_smeta->legendre[3][1][3] = 0.000000E+00;	/* Band 05  SCA 04  Y */
            band_smeta->legendre[4][0][0] = 7.316009E-03;	band_smeta->legendre[4][0][1] = -1.313087E-04;	band_smeta->legendre[4][0][2] = 3.569648E-06;	band_smeta->legendre[4][0][3] = 0.000000E+00;	/* Band 05  SCA 05  X */
            band_smeta->legendre[4][1][0] = 4.779486E-02;	band_smeta->legendre[4][1][1] = -1.005205E-02;	band_smeta->legendre[4][1][2] = 4.945513E-06;	band_smeta->legendre[4][1][3] = 0.000000E+00;	/* Band 05  SCA 05  Y */
            band_smeta->legendre[5][0][0] = -7.139484E-03;	band_smeta->legendre[5][0][1] = -7.031057E-05;	band_smeta->legendre[5][0][2] = 2.654483E-06;	band_smeta->legendre[5][0][3] = 0.000000E+00;	/* Band 05  SCA 06  X */
            band_smeta->legendre[5][1][0] = 2.873013E-02;	band_smeta->legendre[5][1][1] = -1.001012E-02;	band_smeta->legendre[5][1][2] = 2.652368E-06;	band_smeta->legendre[5][1][3] = 0.000000E+00;	/* Band 05  SCA 06  Y */
            band_smeta->legendre[6][0][0] = 7.207137E-03;	band_smeta->legendre[6][0][1] = -2.804846E-05;	band_smeta->legendre[6][0][2] = 3.291859E-06;	band_smeta->legendre[6][0][3] = 0.000000E+00;	/* Band 05  SCA 07  X */
            band_smeta->legendre[6][1][0] = 9.658464E-03;	band_smeta->legendre[6][1][1] = -1.002388E-02;	band_smeta->legendre[6][1][2] = 9.340756E-07;	band_smeta->legendre[6][1][3] = 0.000000E+00;	/* Band 05  SCA 07  Y */
            band_smeta->legendre[7][0][0] = -7.181242E-03;	band_smeta->legendre[7][0][1] = 2.117720E-05;	band_smeta->legendre[7][0][2] = 1.919988E-06;	band_smeta->legendre[7][0][3] = 0.000000E+00;	/* Band 05  SCA 08  X */
            band_smeta->legendre[7][1][0] = -9.381726E-03;	band_smeta->legendre[7][1][1] = -1.000084E-02;	band_smeta->legendre[7][1][2] = -1.522459E-06;	band_smeta->legendre[7][1][3] = 0.000000E+00;	/* Band 05  SCA 08  Y */
            band_smeta->legendre[8][0][0] = 7.242036E-03;	band_smeta->legendre[8][0][1] = 7.672176E-05;	band_smeta->legendre[8][0][2] = 3.365141E-06;	band_smeta->legendre[8][0][3] = 0.000000E+00;	/* Band 05  SCA 09  X */
            band_smeta->legendre[8][1][0] = -2.844051E-02;	band_smeta->legendre[8][1][1] = -1.003335E-02;	band_smeta->legendre[8][1][2] = -2.731339E-06;	band_smeta->legendre[8][1][3] = 0.000000E+00;	/* Band 05  SCA 09  Y */
            band_smeta->legendre[9][0][0] = -7.100034E-03;	band_smeta->legendre[9][0][1] = 1.137035E-04;	band_smeta->legendre[9][0][2] = 3.345888E-06;	band_smeta->legendre[9][0][3] = 0.000000E+00;	/* Band 05  SCA 10  X */
            band_smeta->legendre[9][1][0] = -4.752333E-02;	band_smeta->legendre[9][1][1] = -1.002998E-02;	band_smeta->legendre[9][1][2] = -3.887477E-06;	band_smeta->legendre[9][1][3] = 0.000000E+00;	/* Band 05  SCA 10  Y */
            band_smeta->legendre[10][0][0] = 7.408601E-03;	band_smeta->legendre[10][0][1] = 1.832994E-04;	band_smeta->legendre[10][0][2] = 3.243504E-06;	band_smeta->legendre[10][0][3] = 0.000000E+00;	/* Band 05  SCA 11  X */
            band_smeta->legendre[10][1][0] = -6.664623E-02;	band_smeta->legendre[10][1][1] = -1.008223E-02;	band_smeta->legendre[10][1][2] = -6.298208E-06;	band_smeta->legendre[10][1][3] = 0.000000E+00;	/* Band 05  SCA 11  Y */
            band_smeta->legendre[11][0][0] = -6.905101E-03;	band_smeta->legendre[11][0][1] = 2.040341E-04;	band_smeta->legendre[11][0][2] = 2.331336E-06;	band_smeta->legendre[11][0][3] = 0.000000E+00;	/* Band 05  SCA 12  X */
            band_smeta->legendre[11][1][0] = -8.586151E-02;	band_smeta->legendre[11][1][1] = -1.009786E-02;	band_smeta->legendre[11][1][2] = -6.992614E-06;	band_smeta->legendre[11][1][3] = 0.000000E+00;	/* Band 05  SCA 12  Y */
            band_smeta->legendre[12][0][0] = 7.719478E-03;	band_smeta->legendre[12][0][1] = 2.901260E-04;	band_smeta->legendre[12][0][2] = 4.403218E-06;	band_smeta->legendre[12][0][3] = 0.000000E+00;	/* Band 05  SCA 13  X */
            band_smeta->legendre[12][1][0] = -1.051216E-01;	band_smeta->legendre[12][1][1] = -1.016991E-02;	band_smeta->legendre[12][1][2] = -1.088250E-05;	band_smeta->legendre[12][1][3] = 0.000000E+00;	/* Band 05  SCA 13  Y */
            band_smeta->legendre[13][0][0] = -6.574756E-03;	band_smeta->legendre[13][0][1] = 2.975856E-04;	band_smeta->legendre[13][0][2] = 4.196313E-06;	band_smeta->legendre[13][0][3] = 0.000000E+00;	/* Band 05  SCA 14  X */
            band_smeta->legendre[13][1][0] = -1.245227E-01;	band_smeta->legendre[13][1][1] = -1.020588E-02;	band_smeta->legendre[13][1][2] = -1.075484E-05;	band_smeta->legendre[13][1][3] = 0.000000E+00;	/* Band 05  SCA 14  Y */
            break;
        case 6:
            /* Sudipta new addition for OLI to extract SCA and Det numbers */
            band_smeta->num_detectors = 494;
            /* End Sudipta new addition for OLI */
            band_smeta->legendre[0][0][0] = 1.345912E-02;	band_smeta->legendre[0][0][1] = -3.507767E-04;	band_smeta->legendre[0][0][2] = 3.365172E-06;	band_smeta->legendre[0][0][3] = 0.000000E+00;	/* Band 06  SCA 01  X */
            band_smeta->legendre[0][1][0] = 1.247818E-01;	band_smeta->legendre[0][1][1] = -1.024032E-02;	band_smeta->legendre[0][1][2] = 1.115348E-05;	band_smeta->legendre[0][1][3] = 0.000000E+00;	/* Band 06  SCA 01  Y */
            band_smeta->legendre[1][0][0] = -1.218389E-02;	band_smeta->legendre[1][0][1] = -2.475154E-04;	band_smeta->legendre[1][0][2] = 2.156406E-06;	band_smeta->legendre[1][0][3] = 0.000000E+00;	/* Band 06  SCA 02  X */
            band_smeta->legendre[1][1][0] = 1.054227E-01;	band_smeta->legendre[1][1][1] = -1.013990E-02;	band_smeta->legendre[1][1][2] = 9.126058E-06;	band_smeta->legendre[1][1][3] = 0.000000E+00;	/* Band 06  SCA 02  Y */
            band_smeta->legendre[2][0][0] = 1.305455E-02;	band_smeta->legendre[2][0][1] = -2.415685E-04;	band_smeta->legendre[2][0][2] = 2.632453E-06;	band_smeta->legendre[2][0][3] = 0.000000E+00;	/* Band 06  SCA 03  X */
            band_smeta->legendre[2][1][0] = 8.611989E-02;	band_smeta->legendre[2][1][1] = -1.013291E-02;	band_smeta->legendre[2][1][2] = 8.623916E-06;	band_smeta->legendre[2][1][3] = 0.000000E+00;	/* Band 06  SCA 03  Y */
            band_smeta->legendre[3][0][0] = -1.243446E-02;	band_smeta->legendre[3][0][1] = -1.554256E-04;	band_smeta->legendre[3][0][2] = 2.220429E-06;	band_smeta->legendre[3][0][3] = 0.000000E+00;	/* Band 06  SCA 04  X */
            band_smeta->legendre[3][1][0] = 6.694548E-02;	band_smeta->legendre[3][1][1] = -1.005139E-02;	band_smeta->legendre[3][1][2] = 6.148496E-06;	band_smeta->legendre[3][1][3] = 0.000000E+00;	/* Band 06  SCA 04  Y */
            band_smeta->legendre[4][0][0] = 1.279823E-02;	band_smeta->legendre[4][0][1] = -1.341889E-04;	band_smeta->legendre[4][0][2] = 3.601708E-06;	band_smeta->legendre[4][0][3] = 0.000000E+00;	/* Band 06  SCA 05  X */
            band_smeta->legendre[4][1][0] = 4.779607E-02;	band_smeta->legendre[4][1][1] = -1.006207E-02;	band_smeta->legendre[4][1][2] = 4.764069E-06;	band_smeta->legendre[4][1][3] = 0.000000E+00;	/* Band 06  SCA 05  Y */
            band_smeta->legendre[5][0][0] = -1.257318E-02;	band_smeta->legendre[5][0][1] = -6.746209E-05;	band_smeta->legendre[5][0][2] = 2.480779E-06;	band_smeta->legendre[5][0][3] = 0.000000E+00;	/* Band 06  SCA 06  X */
            band_smeta->legendre[5][1][0] = 2.872349E-02;	band_smeta->legendre[5][1][1] = -1.000256E-02;	band_smeta->legendre[5][1][2] = 2.217992E-06;	band_smeta->legendre[5][1][3] = 0.000000E+00;	/* Band 06  SCA 06  Y */
            band_smeta->legendre[6][0][0] = 1.268643E-02;	band_smeta->legendre[6][0][1] = -2.811526E-05;	band_smeta->legendre[6][0][2] = 3.152612E-06;	band_smeta->legendre[6][0][3] = 0.000000E+00;	/* Band 06  SCA 07  X */
            band_smeta->legendre[6][1][0] = 9.656995E-03;	band_smeta->legendre[6][1][1] = -1.003314E-02;	band_smeta->legendre[6][1][2] = 8.068465E-07;	band_smeta->legendre[6][1][3] = 0.000000E+00;	/* Band 06  SCA 07  Y */
            band_smeta->legendre[7][0][0] = -1.260225E-02;	band_smeta->legendre[7][0][1] = 2.167850E-05;	band_smeta->legendre[7][0][2] = 2.183492E-06;	band_smeta->legendre[7][0][3] = 0.000000E+00;	/* Band 06  SCA 08  X */
            band_smeta->legendre[7][1][0] = -9.385234E-03;	band_smeta->legendre[7][1][1] = -9.993460E-03;	band_smeta->legendre[7][1][2] = -1.362179E-06;	band_smeta->legendre[7][1][3] = 0.000000E+00;	/* Band 06  SCA 08  Y */
            band_smeta->legendre[8][0][0] = 1.272556E-02;	band_smeta->legendre[8][0][1] = 7.837853E-05;	band_smeta->legendre[8][0][2] = 3.701194E-06;	band_smeta->legendre[8][0][3] = 0.000000E+00;	/* Band 06  SCA 09  X */
            band_smeta->legendre[8][1][0] = -2.844315E-02;	band_smeta->legendre[8][1][1] = -1.004286E-02;	band_smeta->legendre[8][1][2] = -2.888487E-06;	band_smeta->legendre[8][1][3] = 0.000000E+00;	/* Band 06  SCA 09  Y */
            band_smeta->legendre[9][0][0] = -1.253014E-02;	band_smeta->legendre[9][0][1] = 1.099448E-04;	band_smeta->legendre[9][0][2] = 3.396994E-06;	band_smeta->legendre[9][0][3] = 0.000000E+00;	/* Band 06  SCA 10  X */
            band_smeta->legendre[9][1][0] = -4.752943E-02;	band_smeta->legendre[9][1][1] = -1.002233E-02;	band_smeta->legendre[9][1][2] = -3.839305E-06;	band_smeta->legendre[9][1][3] = 0.000000E+00;	/* Band 06  SCA 10  Y */
            band_smeta->legendre[10][0][0] = 1.289617E-02;	band_smeta->legendre[10][0][1] = 1.875573E-04;	band_smeta->legendre[10][0][2] = 3.327206E-06;	band_smeta->legendre[10][0][3] = 0.000000E+00;	/* Band 06  SCA 11  X */
            band_smeta->legendre[10][1][0] = -6.665283E-02;	band_smeta->legendre[10][1][1] = -1.009191E-02;	band_smeta->legendre[10][1][2] = -6.373350E-06;	band_smeta->legendre[10][1][3] = 0.000000E+00;	/* Band 06  SCA 11  Y */
            band_smeta->legendre[11][0][0] = -1.234174E-02;	band_smeta->legendre[11][0][1] = 1.996667E-04;	band_smeta->legendre[11][0][2] = 2.215343E-06;	band_smeta->legendre[11][0][3] = 0.000000E+00;	/* Band 06  SCA 12  X */
            band_smeta->legendre[11][1][0] = -8.585719E-02;	band_smeta->legendre[11][1][1] = -1.008995E-02;	band_smeta->legendre[11][1][2] = -7.394567E-06;	band_smeta->legendre[11][1][3] = 0.000000E+00;	/* Band 06  SCA 12  Y */
            band_smeta->legendre[12][0][0] = 1.322300E-02;	band_smeta->legendre[12][0][1] = 2.949716E-04;	band_smeta->legendre[12][0][2] = 4.877904E-06;	band_smeta->legendre[12][0][3] = 0.000000E+00;	/* Band 06  SCA 13  X */
            band_smeta->legendre[12][1][0] = -1.051175E-01;	band_smeta->legendre[12][1][1] = -1.017975E-02;	band_smeta->legendre[12][1][2] = -1.073654E-05;	band_smeta->legendre[12][1][3] = 0.000000E+00;	/* Band 06  SCA 13  Y */
            band_smeta->legendre[13][0][0] = -1.203830E-02;	band_smeta->legendre[13][0][1] = 2.901823E-04;	band_smeta->legendre[13][0][2] = 4.433538E-06;	band_smeta->legendre[13][0][3] = 0.000000E+00;	/* Band 06  SCA 14  X */
            band_smeta->legendre[13][1][0] = -1.245163E-01;	band_smeta->legendre[13][1][1] = -1.019838E-02;	band_smeta->legendre[13][1][2] = -1.073917E-05;	band_smeta->legendre[13][1][3] = 0.000000E+00;	/* Band 06  SCA 14  Y */
            break;
        case 7:
            /* Sudipta new addition for OLI to extract SCA and Det numbers */
            band_smeta->num_detectors = 494;
            /* End Sudipta new addition for OLI */
            band_smeta->legendre[0][0][0] = 1.222355E-02;	band_smeta->legendre[0][0][1] = -3.488484E-04;	band_smeta->legendre[0][0][2] = 3.503357E-06;	band_smeta->legendre[0][0][3] = 0.000000E+00;	/* Band 07  SCA 01  X */
            band_smeta->legendre[0][1][0] = 1.247830E-01;	band_smeta->legendre[0][1][1] = -1.023845E-02;	band_smeta->legendre[0][1][2] = 1.085608E-05;	band_smeta->legendre[0][1][3] = 0.000000E+00;	/* Band 07  SCA 01  Y */
            band_smeta->legendre[1][0][0] = -1.095263E-02;	band_smeta->legendre[1][0][1] = -2.488298E-04;	band_smeta->legendre[1][0][2] = 2.346719E-06;	band_smeta->legendre[1][0][3] = 0.000000E+00;	/* Band 07  SCA 02  X */
            band_smeta->legendre[1][1][0] = 1.054242E-01;	band_smeta->legendre[1][1][1] = -1.014190E-02;	band_smeta->legendre[1][1][2] = 9.456518E-06;	band_smeta->legendre[1][1][3] = 0.000000E+00;	/* Band 07  SCA 02  Y */
            band_smeta->legendre[2][0][0] = 1.182350E-02;	band_smeta->legendre[2][0][1] = -2.402396E-04;	band_smeta->legendre[2][0][2] = 2.531902E-06;	band_smeta->legendre[2][0][3] = 0.000000E+00;	/* Band 07  SCA 03  X */
            band_smeta->legendre[2][1][0] = 8.612055E-02;	band_smeta->legendre[2][1][1] = -1.013097E-02;	band_smeta->legendre[2][1][2] = 8.766255E-06;	band_smeta->legendre[2][1][3] = 0.000000E+00;	/* Band 07  SCA 03  Y */
            band_smeta->legendre[3][0][0] = -1.120772E-02;	band_smeta->legendre[3][0][1] = -1.560388E-04;	band_smeta->legendre[3][0][2] = 2.279632E-06;	band_smeta->legendre[3][0][3] = 0.000000E+00;	/* Band 07  SCA 04  X */
            band_smeta->legendre[3][1][0] = 6.694686E-02;	band_smeta->legendre[3][1][1] = -1.005347E-02;	band_smeta->legendre[3][1][2] = 5.960465E-06;	band_smeta->legendre[3][1][3] = 0.000000E+00;	/* Band 07  SCA 04  Y */
            band_smeta->legendre[4][0][0] = 1.157019E-02;	band_smeta->legendre[4][0][1] = -1.332875E-04;	band_smeta->legendre[4][0][2] = 3.610566E-06;	band_smeta->legendre[4][0][3] = 0.000000E+00;	/* Band 07  SCA 05  X */
            band_smeta->legendre[4][1][0] = 4.779614E-02;	band_smeta->legendre[4][1][1] = -1.006004E-02;	band_smeta->legendre[4][1][2] = 4.781929E-06;	band_smeta->legendre[4][1][3] = 0.000000E+00;	/* Band 07  SCA 05  Y */
            band_smeta->legendre[5][0][0] = -1.134847E-02;	band_smeta->legendre[5][0][1] = -6.763984E-05;	band_smeta->legendre[5][0][2] = 2.478512E-06;	band_smeta->legendre[5][0][3] = 0.000000E+00;	/* Band 07  SCA 06  X */
            band_smeta->legendre[5][1][0] = 2.872411E-02;	band_smeta->legendre[5][1][1] = -1.000435E-02;	band_smeta->legendre[5][1][2] = 2.127892E-06;	band_smeta->legendre[5][1][3] = 0.000000E+00;	/* Band 07  SCA 06  Y */
            band_smeta->legendre[6][0][0] = 1.145985E-02;	band_smeta->legendre[6][0][1] = -2.758350E-05;	band_smeta->legendre[6][0][2] = 2.975109E-06;	band_smeta->legendre[6][0][3] = 0.000000E+00;	/* Band 07  SCA 07  X */
            band_smeta->legendre[6][1][0] = 9.656917E-03;	band_smeta->legendre[6][1][1] = -1.003119E-02;	band_smeta->legendre[6][1][2] = 9.144357E-07;	band_smeta->legendre[6][1][3] = 0.000000E+00;	/* Band 07  SCA 07  Y */
            band_smeta->legendre[7][0][0] = -1.137774E-02;	band_smeta->legendre[7][0][1] = 2.186020E-05;	band_smeta->legendre[7][0][2] = 2.301565E-06;	band_smeta->legendre[7][0][3] = 0.000000E+00;	/* Band 07  SCA 08  X */
            band_smeta->legendre[7][1][0] = -9.385022E-03;	band_smeta->legendre[7][1][1] = -9.995444E-03;	band_smeta->legendre[7][1][2] = -1.412133E-06;	band_smeta->legendre[7][1][3] = 0.000000E+00;	/* Band 07  SCA 08  Y */
            band_smeta->legendre[8][0][0] = 1.149831E-02;	band_smeta->legendre[8][0][1] = 7.811905E-05;	band_smeta->legendre[8][0][2] = 3.758388E-06;	band_smeta->legendre[8][0][3] = 0.000000E+00;	/* Band 07  SCA 09  X */
            band_smeta->legendre[8][1][0] = -2.844359E-02;	band_smeta->legendre[8][1][1] = -1.004084E-02;	band_smeta->legendre[8][1][2] = -2.853792E-06;	band_smeta->legendre[8][1][3] = 0.000000E+00;	/* Band 07  SCA 09  Y */
            band_smeta->legendre[9][0][0] = -1.130446E-02;	band_smeta->legendre[9][0][1] = 1.109295E-04;	band_smeta->legendre[9][0][2] = 3.599788E-06;	band_smeta->legendre[9][0][3] = 0.000000E+00;	/* Band 07  SCA 10  X */
            band_smeta->legendre[9][1][0] = -4.752999E-02;	band_smeta->legendre[9][1][1] = -1.002429E-02;	band_smeta->legendre[9][1][2] = -3.890668E-06;	band_smeta->legendre[9][1][3] = 0.000000E+00;	/* Band 07  SCA 10  Y */
            band_smeta->legendre[10][0][0] = 1.166728E-02;	band_smeta->legendre[10][0][1] = 1.869466E-04;	band_smeta->legendre[10][0][2] = 3.371033E-06;	band_smeta->legendre[10][0][3] = 0.000000E+00;	/* Band 07  SCA 11  X */
            band_smeta->legendre[10][1][0] = -6.665389E-02;	band_smeta->legendre[10][1][1] = -1.008986E-02;	band_smeta->legendre[10][1][2] = -6.451903E-06;	band_smeta->legendre[10][1][3] = 0.000000E+00;	/* Band 07  SCA 11  Y */
            band_smeta->legendre[11][0][0] = -1.111281E-02;	band_smeta->legendre[11][0][1] = 2.009141E-04;	band_smeta->legendre[11][0][2] = 2.472552E-06;	band_smeta->legendre[11][0][3] = 0.000000E+00;	/* Band 07  SCA 12  X */
            band_smeta->legendre[11][1][0] = -8.585818E-02;	band_smeta->legendre[11][1][1] = -1.009201E-02;	band_smeta->legendre[11][1][2] = -7.282292E-06;	band_smeta->legendre[11][1][3] = 0.000000E+00;	/* Band 07  SCA 12  Y */
            band_smeta->legendre[12][0][0] = 1.199052E-02;	band_smeta->legendre[12][0][1] = 2.939047E-04;	band_smeta->legendre[12][0][2] = 4.901800E-06;	band_smeta->legendre[12][0][3] = 0.000000E+00;	/* Band 07  SCA 13  X */
            band_smeta->legendre[12][1][0] = -1.051191E-01;	band_smeta->legendre[12][1][1] = -1.017766E-02;	band_smeta->legendre[12][1][2] = -1.058382E-05;	band_smeta->legendre[12][1][3] = 0.000000E+00;	/* Band 07  SCA 13  Y */
            band_smeta->legendre[13][0][0] = -1.080512E-02;	band_smeta->legendre[13][0][1] = 2.924805E-04;	band_smeta->legendre[13][0][2] = 4.558129E-06;	band_smeta->legendre[13][0][3] = 0.000000E+00;	/* Band 07  SCA 14  X */
            band_smeta->legendre[13][1][0] = -1.245180E-01;	band_smeta->legendre[13][1][1] = -1.020024E-02;	band_smeta->legendre[13][1][2] = -1.066432E-05;	band_smeta->legendre[13][1][3] = 0.000000E+00;	/* Band 07  SCA 14  Y */
            break;
        case 8:
            /* Sudipta new addition for OLI to extract SCA and Det numbers */
            band_smeta->num_detectors = 988;
            /* End Sudipta new addition for OLI */
            band_smeta->legendre[0][0][0] = 4.252524E-03;	band_smeta->legendre[0][0][1] = -3.375425E-04;	band_smeta->legendre[0][0][2] = 3.093750E-06;	band_smeta->legendre[0][0][3] = 0.000000E+00;	/* Band 08  SCA 01  X */
            band_smeta->legendre[0][1][0] = 1.247783E-01;	band_smeta->legendre[0][1][1] = -1.023544E-02;	band_smeta->legendre[0][1][2] = 1.111046E-05;	band_smeta->legendre[0][1][3] = 0.000000E+00;	/* Band 08  SCA 01  Y */
            band_smeta->legendre[1][0][0] = -3.029343E-03;	band_smeta->legendre[1][0][1] = -2.585621E-04;	band_smeta->legendre[1][0][2] = 2.478111E-06;	band_smeta->legendre[1][0][3] = 0.000000E+00;	/* Band 08  SCA 02  X */
            band_smeta->legendre[1][1][0] = 1.054291E-01;	band_smeta->legendre[1][1][1] = -1.016342E-02;	band_smeta->legendre[1][1][2] = 9.522094E-06;	band_smeta->legendre[1][1][3] = 0.000000E+00;	/* Band 08  SCA 02  Y */
            band_smeta->legendre[2][0][0] = 3.884395E-03;	band_smeta->legendre[2][0][1] = -2.339566E-04;	band_smeta->legendre[2][0][2] = 2.524238E-06;	band_smeta->legendre[2][0][3] = 0.000000E+00;	/* Band 08  SCA 03  X */
            band_smeta->legendre[2][1][0] = 8.611699E-02;	band_smeta->legendre[2][1][1] = -1.012730E-02;	band_smeta->legendre[2][1][2] = 8.254239E-06;	band_smeta->legendre[2][1][3] = 0.000000E+00;	/* Band 08  SCA 03  Y */
            band_smeta->legendre[3][0][0] = -3.307669E-03;	band_smeta->legendre[3][0][1] = -1.635348E-04;	band_smeta->legendre[3][0][2] = 2.517627E-06;	band_smeta->legendre[3][0][3] = 0.000000E+00;	/* Band 08  SCA 04  X */
            band_smeta->legendre[3][1][0] = 6.694935E-02;	band_smeta->legendre[3][1][1] = -1.007514E-02;	band_smeta->legendre[3][1][2] = 6.410045E-06;	band_smeta->legendre[3][1][3] = 0.000000E+00;	/* Band 08  SCA 04  Y */
            band_smeta->legendre[4][0][0] = 3.645584E-03;	band_smeta->legendre[4][0][1] = -1.298436E-04;	band_smeta->legendre[4][0][2] = 3.693088E-06;	band_smeta->legendre[4][0][3] = 0.000000E+00;	/* Band 08  SCA 05  X */
            band_smeta->legendre[4][1][0] = 4.779417E-02;	band_smeta->legendre[4][1][1] = -1.005610E-02;	band_smeta->legendre[4][1][2] = 5.053775E-06;	band_smeta->legendre[4][1][3] = 0.000000E+00;	/* Band 08  SCA 05  Y */
            band_smeta->legendre[5][0][0] = -3.452992E-03;	band_smeta->legendre[5][0][1] = -7.148948E-05;	band_smeta->legendre[5][0][2] = 3.033732E-06;	band_smeta->legendre[5][0][3] = 0.000000E+00;	/* Band 08  SCA 06  X */
            band_smeta->legendre[5][1][0] = 2.873058E-02;	band_smeta->legendre[5][1][1] = -1.002593E-02;	band_smeta->legendre[5][1][2] = 2.745292E-06;	band_smeta->legendre[5][1][3] = 0.000000E+00;	/* Band 08  SCA 06  Y */
            band_smeta->legendre[6][0][0] = 3.540947E-03;	band_smeta->legendre[6][0][1] = -2.783162E-05;	band_smeta->legendre[6][0][2] = 3.269470E-06;	band_smeta->legendre[6][0][3] = 0.000000E+00;	/* Band 08  SCA 07  X */
            band_smeta->legendre[6][1][0] = 9.658145E-03;	band_smeta->legendre[6][1][1] = -1.002781E-02;	band_smeta->legendre[6][1][2] = 1.039589E-06;	band_smeta->legendre[6][1][3] = 0.000000E+00;	/* Band 08  SCA 07  Y */
            band_smeta->legendre[7][0][0] = -3.495677E-03;	band_smeta->legendre[7][0][1] = 2.132260E-05;	band_smeta->legendre[7][0][2] = 2.430337E-06;	band_smeta->legendre[7][0][3] = 0.000000E+00;	/* Band 08  SCA 08  X */
            band_smeta->legendre[7][1][0] = -9.381522E-03;	band_smeta->legendre[7][1][1] = -1.001653E-02;	band_smeta->legendre[7][1][2] = -1.630559E-06;	band_smeta->legendre[7][1][3] = 0.000000E+00;	/* Band 08  SCA 08  Y */
            band_smeta->legendre[8][0][0] = 3.575055E-03;	band_smeta->legendre[8][0][1] = 7.565249E-05;	band_smeta->legendre[8][0][2] = 3.355898E-06;	band_smeta->legendre[8][0][3] = 0.000000E+00;	/* Band 08  SCA 09  X */
            band_smeta->legendre[8][1][0] = -2.844108E-02;	band_smeta->legendre[8][1][1] = -1.003763E-02;	band_smeta->legendre[8][1][2] = -2.853618E-06;	band_smeta->legendre[8][1][3] = 0.000000E+00;	/* Band 08  SCA 09  Y */
            band_smeta->legendre[9][0][0] = -3.410597E-03;	band_smeta->legendre[9][0][1] = 1.155142E-04;	band_smeta->legendre[9][0][2] = 3.409904E-06;	band_smeta->legendre[9][0][3] = 0.000000E+00;	/* Band 08  SCA 10  X */
            band_smeta->legendre[9][1][0] = -4.752315E-02;	band_smeta->legendre[9][1][1] = -1.004586E-02;	band_smeta->legendre[9][1][2] = -4.291685E-06;	band_smeta->legendre[9][1][3] = 0.000000E+00;	/* Band 08  SCA 10  Y */
            band_smeta->legendre[10][0][0] = 3.735765E-03;	band_smeta->legendre[10][0][1] = 1.805677E-04;	band_smeta->legendre[10][0][2] = 3.377491E-06;	band_smeta->legendre[10][0][3] = 0.000000E+00;	/* Band 08  SCA 11  X */
            band_smeta->legendre[10][1][0] = -6.664703E-02;	band_smeta->legendre[10][1][1] = -1.008641E-02;	band_smeta->legendre[10][1][2] = -6.321028E-06;	band_smeta->legendre[10][1][3] = 0.000000E+00;	/* Band 08  SCA 11  Y */
            band_smeta->legendre[11][0][0] = -3.206932E-03;	band_smeta->legendre[11][0][1] = 2.077678E-04;	band_smeta->legendre[11][0][2] = 2.716352E-06;	band_smeta->legendre[11][0][3] = 0.000000E+00;	/* Band 08  SCA 12  X */
            band_smeta->legendre[11][1][0] = -8.586160E-02;	band_smeta->legendre[11][1][1] = -1.011377E-02;	band_smeta->legendre[11][1][2] = -7.109927E-06;	band_smeta->legendre[11][1][3] = 0.000000E+00;	/* Band 08  SCA 12  Y */
            band_smeta->legendre[12][0][0] = 4.033433E-03;	band_smeta->legendre[12][0][1] = 2.857025E-04;	band_smeta->legendre[12][0][2] = 4.541956E-06;	band_smeta->legendre[12][0][3] = 0.000000E+00;	/* Band 08  SCA 13  X */
            band_smeta->legendre[12][1][0] = -1.051228E-01;	band_smeta->legendre[12][1][1] = -1.017396E-02;	band_smeta->legendre[12][1][2] = -1.083649E-05;	band_smeta->legendre[12][1][3] = 0.000000E+00;	/* Band 08  SCA 13  Y */
            band_smeta->legendre[13][0][0] = -2.862726E-03;	band_smeta->legendre[13][0][1] = 3.030336E-04;	band_smeta->legendre[13][0][2] = 4.139959E-06;	band_smeta->legendre[13][0][3] = 0.000000E+00;	/* Band 08  SCA 14  X */
            band_smeta->legendre[13][1][0] = -1.245235E-01;	band_smeta->legendre[13][1][1] = -1.022128E-02;	band_smeta->legendre[13][1][2] = -1.074760E-05;	band_smeta->legendre[13][1][3] = 0.000000E+00;	/* Band 08  SCA 14  Y */
            break;
        case 9:
            /* Sudipta new addition for OLI to extract SCA and Det numbers */
            band_smeta->num_detectors = 494;
            /* End Sudipta new addition for OLI */
            band_smeta->legendre[0][0][0] = 1.469991E-02;	band_smeta->legendre[0][0][1] = -3.526521E-04;	band_smeta->legendre[0][0][2] = 2.996944E-06;	band_smeta->legendre[0][0][3] = 0.000000E+00;	/* Band 09  SCA 01  X */
            band_smeta->legendre[0][1][0] = 1.247814E-01;	band_smeta->legendre[0][1][1] = -1.024292E-02;	band_smeta->legendre[0][1][2] = 1.250792E-05;	band_smeta->legendre[0][1][3] = 0.000000E+00;	/* Band 09  SCA 01  Y */
            band_smeta->legendre[1][0][0] = -1.340998E-02;	band_smeta->legendre[1][0][1] = -2.443003E-04;	band_smeta->legendre[1][0][2] = 3.343894E-06;	band_smeta->legendre[1][0][3] = 0.000000E+00;	/* Band 09  SCA 02  X */
            band_smeta->legendre[1][1][0] = 1.054212E-01;	band_smeta->legendre[1][1][1] = -1.013747E-02;	band_smeta->legendre[1][1][2] = 8.813593E-06;	band_smeta->legendre[1][1][3] = 0.000000E+00;	/* Band 09  SCA 02  Y */
            band_smeta->legendre[2][0][0] = 1.428952E-02;	band_smeta->legendre[2][0][1] = -2.433210E-04;	band_smeta->legendre[2][0][2] = 2.593979E-06;	band_smeta->legendre[2][0][3] = 0.000000E+00;	/* Band 09  SCA 03  X */
            band_smeta->legendre[2][1][0] = 8.611970E-02;	band_smeta->legendre[2][1][1] = -1.013474E-02;	band_smeta->legendre[2][1][2] = 8.225067E-06;	band_smeta->legendre[2][1][3] = 0.000000E+00;	/* Band 09  SCA 03  Y */
            band_smeta->legendre[3][0][0] = -1.365834E-02;	band_smeta->legendre[3][0][1] = -1.516531E-04;	band_smeta->legendre[3][0][2] = 1.819539E-06;	band_smeta->legendre[3][0][3] = 0.000000E+00;	/* Band 09  SCA 04  X */
            band_smeta->legendre[3][1][0] = 6.694384E-02;	band_smeta->legendre[3][1][1] = -1.004983E-02;	band_smeta->legendre[3][1][2] = 5.962782E-06;	band_smeta->legendre[3][1][3] = 0.000000E+00;	/* Band 09  SCA 04  Y */
            band_smeta->legendre[4][0][0] = 1.403122E-02;	band_smeta->legendre[4][0][1] = -1.362427E-04;	band_smeta->legendre[4][0][2] = 4.626827E-06;	band_smeta->legendre[4][0][3] = 0.000000E+00;	/* Band 09  SCA 05  X */
            band_smeta->legendre[4][1][0] = 4.779595E-02;	band_smeta->legendre[4][1][1] = -1.006435E-02;	band_smeta->legendre[4][1][2] = 4.306440E-06;	band_smeta->legendre[4][1][3] = 0.000000E+00;	/* Band 09  SCA 05  Y */
            band_smeta->legendre[5][0][0] = -1.379413E-02;	band_smeta->legendre[5][0][1] = -6.633253E-05;	band_smeta->legendre[5][0][2] = 2.684987E-06;	band_smeta->legendre[5][0][3] = 0.000000E+00;	/* Band 09  SCA 06  X */
            band_smeta->legendre[5][1][0] = 2.872240E-02;	band_smeta->legendre[5][1][1] = -1.000079E-02;	band_smeta->legendre[5][1][2] = 1.858352E-06;	band_smeta->legendre[5][1][3] = 0.000000E+00;	/* Band 09  SCA 06  Y */
            band_smeta->legendre[6][0][0] = 1.391807E-02;	band_smeta->legendre[6][0][1] = -2.867362E-05;	band_smeta->legendre[6][0][2] = 4.334720E-06;	band_smeta->legendre[6][0][3] = 0.000000E+00;	/* Band 09  SCA 07  X */
            band_smeta->legendre[6][1][0] = 9.655709E-03;	band_smeta->legendre[6][1][1] = -1.003472E-02;	band_smeta->legendre[6][1][2] = 1.728144E-06;	band_smeta->legendre[6][1][3] = 0.000000E+00;	/* Band 09  SCA 07  Y */
            band_smeta->legendre[7][0][0] = -1.382212E-02;	band_smeta->legendre[7][0][1] = 2.140439E-05;	band_smeta->legendre[7][0][2] = 2.211910E-06;	band_smeta->legendre[7][0][3] = 0.000000E+00;	/* Band 09  SCA 08  X */
            band_smeta->legendre[7][1][0] = -9.385835E-03;	band_smeta->legendre[7][1][1] = -9.991244E-03;	band_smeta->legendre[7][1][2] = -9.635907E-07;	band_smeta->legendre[7][1][3] = 0.000000E+00;	/* Band 09  SCA 08  Y */
            band_smeta->legendre[8][0][0] = 1.395698E-02;	band_smeta->legendre[8][0][1] = 7.925795E-05;	band_smeta->legendre[8][0][2] = 3.245003E-06;	band_smeta->legendre[8][0][3] = 0.000000E+00;	/* Band 09  SCA 09  X */
            band_smeta->legendre[8][1][0] = -2.844433E-02;	band_smeta->legendre[8][1][1] = -1.004471E-02;	band_smeta->legendre[8][1][2] = -2.439607E-06;	band_smeta->legendre[8][1][3] = 0.000000E+00;	/* Band 09  SCA 09  Y */
            band_smeta->legendre[9][0][0] = -1.375203E-02;	band_smeta->legendre[9][0][1] = 1.076389E-04;	band_smeta->legendre[9][0][2] = 2.116246E-06;	band_smeta->legendre[9][0][3] = 0.000000E+00;	/* Band 09  SCA 10  X */
            band_smeta->legendre[9][1][0] = -4.753074E-02;	band_smeta->legendre[9][1][1] = -1.002063E-02;	band_smeta->legendre[9][1][2] = -3.717124E-06;	band_smeta->legendre[9][1][3] = 0.000000E+00;	/* Band 09  SCA 10  Y */
            band_smeta->legendre[10][0][0] = 1.413111E-02;	band_smeta->legendre[10][0][1] = 1.889807E-04;	band_smeta->legendre[10][0][2] = 3.500592E-06;	band_smeta->legendre[10][0][3] = 0.000000E+00;	/* Band 09  SCA 11  X */
            band_smeta->legendre[10][1][0] = -6.665388E-02;	band_smeta->legendre[10][1][1] = -1.009329E-02;	band_smeta->legendre[10][1][2] = -6.154595E-06;	band_smeta->legendre[10][1][3] = 0.000000E+00;	/* Band 09  SCA 11  Y */
            band_smeta->legendre[11][0][0] = -1.356603E-02;	band_smeta->legendre[11][0][1] = 1.957164E-04;	band_smeta->legendre[11][0][2] = 2.889459E-06;	band_smeta->legendre[11][0][3] = 0.000000E+00;	/* Band 09  SCA 12  X */
            band_smeta->legendre[11][1][0] = -8.585872E-02;	band_smeta->legendre[11][1][1] = -1.008862E-02;	band_smeta->legendre[11][1][2] = -7.131130E-06;	band_smeta->legendre[11][1][3] = 0.000000E+00;	/* Band 09  SCA 12  Y */
            band_smeta->legendre[12][0][0] = 1.446188E-02;	band_smeta->legendre[12][0][1] = 2.980366E-04;	band_smeta->legendre[12][0][2] = 5.004141E-06;	band_smeta->legendre[12][0][3] = 0.000000E+00;	/* Band 09  SCA 13  X */
            band_smeta->legendre[12][1][0] = -1.051188E-01;	band_smeta->legendre[12][1][1] = -1.018152E-02;	band_smeta->legendre[12][1][2] = -1.215252E-05;	band_smeta->legendre[12][1][3] = 0.000000E+00;	/* Band 09  SCA 13  Y */
            band_smeta->legendre[13][0][0] = -1.326883E-02;	band_smeta->legendre[13][0][1] = 2.858092E-04;	band_smeta->legendre[13][0][2] = 4.411644E-06;	band_smeta->legendre[13][0][3] = 0.000000E+00;	/* Band 09  SCA 14  X */
            band_smeta->legendre[13][1][0] = -1.245172E-01;	band_smeta->legendre[13][1][1] = -1.019636E-02;	band_smeta->legendre[13][1][2] = -1.009994E-05;	band_smeta->legendre[13][1][3] = 0.000000E+00;	/* Band 09  SCA 14  Y */
            break;
        case 10:
            band_smeta->nsca = 3;
            /* Sudipta new addition for OLI to extract SCA and Det numbers */
            band_smeta->num_detectors = 640;
            /* End Sudipta new addition for OLI */
            band_smeta->align[0][0] =  0.999995230;
            band_smeta->align[0][1] =  0.002234010;
            band_smeta->align[0][2] = -0.002132570;
            band_smeta->align[1][0] = -0.002233663;
            band_smeta->align[1][1] =  0.999997491;
            band_smeta->align[1][2] =  0.000165723;
            band_smeta->align[2][0] =  0.002132934;
            band_smeta->align[2][1] = -0.000160959;
            band_smeta->align[2][2] =  0.999997712;
            band_smeta->legendre[0][0][0] = -4.600619E-02;	band_smeta->legendre[0][0][1] = 5.355540E-05;	band_smeta->legendre[0][0][2] = -2.367151E-05;	band_smeta->legendre[0][0][3] = 2.580050E-06;	/* Band 10  SCA 01  X */
            band_smeta->legendre[0][1][0] = -8.639810E-02;	band_smeta->legendre[0][1][1] = 4.553034E-02;	band_smeta->legendre[0][1][2] = -1.224341E-04;	band_smeta->legendre[0][1][3] = 2.005583E-05;	/* Band 10  SCA 01  Y */
            band_smeta->legendre[1][0][0] = 4.041600E-02;	band_smeta->legendre[1][0][1] = -6.367114E-05;	band_smeta->legendre[1][0][2] = 1.486799E-05;	band_smeta->legendre[1][0][3] = 8.984839E-07;	/* Band 10  SCA 02  X */
            band_smeta->legendre[1][1][0] = 7.383249E-04;	band_smeta->legendre[1][1][1] = 4.520092E-02;	band_smeta->legendre[1][1][2] = 1.186375E-06;	band_smeta->legendre[1][1][3] = 1.059907E-05;	/* Band 10  SCA 02  Y */
            band_smeta->legendre[2][0][0] = -4.582177E-02;	band_smeta->legendre[2][0][1] = -1.780177E-04;	band_smeta->legendre[2][0][2] = -2.521064E-05;	band_smeta->legendre[2][0][3] = -3.017250E-06;	/* Band 10  SCA 03  X */
            band_smeta->legendre[2][1][0] = 8.748055E-02;	band_smeta->legendre[2][1][1] = 4.553768E-02;	band_smeta->legendre[2][1][2] = 1.243330E-04;	band_smeta->legendre[2][1][3] = 1.840046E-05;	/* Band 10  SCA 03  Y */
            break;
        case 11:
            band_smeta->nsca = 3;
            /* Sudipta new addition for OLI to extract SCA and Det numbers */
            band_smeta->num_detectors = 640;
            /* End Sudipta new addition for OLI */
            band_smeta->align[0][0] =  0.999995230;
            band_smeta->align[0][1] =  0.002234010;
            band_smeta->align[0][2] = -0.002132570;
            band_smeta->align[1][0] = -0.002233663;
            band_smeta->align[1][1] =  0.999997491;
            band_smeta->align[1][2] =  0.000165723;
            band_smeta->align[2][0] =  0.002132934;
            band_smeta->align[2][1] = -0.000160959;
            band_smeta->align[2][2] =  0.999997712;
            band_smeta->legendre[0][0][0] = -2.818374E-02;	band_smeta->legendre[0][0][1] = 1.420312E-05;	band_smeta->legendre[0][0][2] = -1.583177E-05;	band_smeta->legendre[0][0][3] = 4.703008E-07;	/* Band 11  SCA 01  X */
            band_smeta->legendre[0][1][0] = -8.634943E-02;	band_smeta->legendre[0][1][1] = 4.550868E-02;	band_smeta->legendre[0][1][2] = -1.188939E-04;	band_smeta->legendre[0][1][3] = 2.004849E-05;	/* Band 11  SCA 01  Y */
            band_smeta->legendre[1][0][0] = 2.190447E-02;	band_smeta->legendre[1][0][1] = -6.403253E-05;	band_smeta->legendre[1][0][2] = 9.479177E-06;	band_smeta->legendre[1][0][3] = -8.414291E-07;	/* Band 11  SCA 02  X */
            band_smeta->legendre[1][1][0] = 7.106738E-04;	band_smeta->legendre[1][1][1] = 4.518972E-02;	band_smeta->legendre[1][1][2] = 2.959635E-06;	band_smeta->legendre[1][1][3] = 9.602212E-06;	/* Band 11  SCA 02  Y */
            band_smeta->legendre[2][0][0] = -2.910073E-02;	band_smeta->legendre[2][0][1] = -1.301388E-04;	band_smeta->legendre[2][0][2] = -1.422378E-05;	band_smeta->legendre[2][0][3] = -2.167499E-06;	/* Band 11  SCA 03  X */
            band_smeta->legendre[2][1][0] = 8.747419E-02;	band_smeta->legendre[2][1][1] = 4.551648E-02;	band_smeta->legendre[2][1][2] = 1.202780E-04;	band_smeta->legendre[2][1][3] = 1.648944E-05;	/* Band 11  SCA 03  Y */
            break;
        default:
            IAS_LOG_ERROR("No LOS model for user band number %d.", band_smeta->band);
            return(ERROR);
    }

    return(SUCCESS);
}


int smeta_load_band_model_ls(
    SMETA		*smeta,			/* Product metadata input                    */
    SMETA_BAND_LS		*band_smeta )		/* Band metadata structure to load           */
{
    int l5_bumper_date[] = { 2002, 3, 27 };	/* Date the L5 TM was switched to bumper mode */
    int l7_bumper_date[] = { 2007, 3, 31 };	/* Date the L7 ETM+ was switched to bumper mode */
    double *Along_Scan_Band_Offsets;
    double *Across_Scan_Band_Offsets;
    double L7_Along_Scan_Band_Offsets[IAS_MAX_NBANDS_LS] =
           {+3627.908,+2564.326,+1500.619,+438.054,-2579.286,-4073.554,-1474.955,+4692.000};
    double L7_Across_Scan_Band_Offsets[IAS_MAX_NBANDS_LS] =
           {+1.255,+0.592,-0.028,-1.466,+17.242,+32.479,+17.042,+0.000};
    double L5_Along_Scan_Band_Offsets[IAS_MAX_NBANDS_LS] =
           {+3616.293,+2554.010,+1491.440,+429.773,-2576.042,-4077.805,-1473.056};
    double L5_Across_Scan_Band_Offsets[IAS_MAX_NBANDS_LS] =
           {-12.147,-12.250,-13.203,-12.902,+4.675,-6.354,+5.719};
    double L4_Along_Scan_Band_Offsets[IAS_MAX_NBANDS_LS] =
           {+3571.222,+2510.043,+1448.742,+388.334,-2600.691,-4078.296,-1496.897};
    double L4_Across_Scan_Band_Offsets[IAS_MAX_NBANDS_LS] =
           {+16.008,+16.015,+17.933,+18.136,-0.850,-16.723,-1.307};
    double fs2m, fm2e, rs2m, rm2e;		/* First half/second half scan angles */
    int bumper_days;				/* Days since switch to bumper mode */

    /* Set defaults based upon spacecraft ID */
    band_smeta->nsca   = 1;

	if ( smeta->spacecraft_id == IAS_L5 )
    {
		band_smeta->nscans = 374;
		band_smeta->align[0][0] =  9.99999851E-01;
		band_smeta->align[0][1] = +5.45640973E-04;
		band_smeta->align[0][2] = -9.00000000E-06;
		band_smeta->align[1][0] = -5.45647569E-04;
		band_smeta->align[1][1] =  9.99999570E-01;
		band_smeta->align[1][2] = -7.49999930E-04;
		band_smeta->align[2][0] = +8.59076544E-06;
		band_smeta->align[2][1] = +7.50004729E-04;
		band_smeta->align[2][2] =  9.99999719E-01;
		Along_Scan_Band_Offsets = L5_Along_Scan_Band_Offsets;
		Across_Scan_Band_Offsets = L5_Across_Scan_Band_Offsets;
	}
	else
    {
        band_smeta->nscans = 375;
        band_smeta->align[0][0] =  9.99999845E-01;
        band_smeta->align[0][1] = +1.18363752E-04;
        band_smeta->align[0][2] = +5.43986578E-04;
        band_smeta->align[1][0] = -1.18213574E-04;
        band_smeta->align[1][1] =  9.99999955E-01;
        band_smeta->align[1][2] = -2.76092898E-04;
        band_smeta->align[2][0] = -5.44019232E-04;
        band_smeta->align[2][1] = +2.76028548E-04;
        band_smeta->align[2][2] =  9.99999814E-01;
        Along_Scan_Band_Offsets = L7_Along_Scan_Band_Offsets;
        Across_Scan_Band_Offsets = L7_Across_Scan_Band_Offsets;
    }

    band_smeta->center_sample = 0.0;
    band_smeta->sample_slope = 0.0;

    if ( smeta->sensor_mode == TM_BUMPER )
    {
        if ( smeta->spacecraft_id == IAS_L5 )
        {
            bumper_days =  delta_date( l5_bumper_date, smeta->acq_date );
            fs2m = 67764.2 + 0.27638 * bumper_days;
            fm2e = 69765.4 + 0.25420 * bumper_days;
            rs2m = 67943.7 + 0.34734 * bumper_days;
            rm2e = 69275.2 + 0.07921 * bumper_days;
        }
        else
        {
            bumper_days =  delta_date( l7_bumper_date, smeta->acq_date );
            fs2m = 68407.8 + 0.22954 * bumper_days;
            fm2e = 69116.3 + 0.42045 * bumper_days;
            rs2m = 68281.3 + 0.46290 * bumper_days;
            rm2e = 69001.8 + 0.14103 * bumper_days;
        }
    }
    else
    {
        if ( smeta->spacecraft_id == IAS_L5 )
        {
            fs2m = 67171.0;
            fm2e = 67159.0;
            rs2m = 67159.0;
            rm2e = 67171.0;
        }
        else
        {
            fs2m = 67167.9;
            fm2e = 67145.8;
            rs2m = 67145.8;
            rm2e = 67167.9;
        }
    }

    /* Scale to radians */
    fs2m *= 2.0/1000000.0;
    fm2e *= 2.0/1000000.0;
    rs2m *= 2.0/1000000.0;
    rm2e *= 2.0/1000000.0;

    /* Switch on the current user band number */
    band_smeta->fascan    = ( fs2m > rm2e ? fs2m : rm2e );
    band_smeta->rascan    = ( fm2e > rs2m ? fm2e : rs2m );

    switch ( band_smeta->band )
    {
        case 0:
            band_smeta->nsamps   = 6320.0;
            band_smeta->nlines   = 16.0;
            band_smeta->afov = 42.5e-6;
            band_smeta->xfov = 42.5e-6;
            band_smeta->aoffset  = 0.0;
            band_smeta->xoffset  = 0.0;
            band_smeta->xscan    = band_smeta->xfov * (band_smeta->nlines - 1.0);
            break;
        case 1:
            band_smeta->nsamps   = 6320.0;
            band_smeta->nlines   = 16.0;
            band_smeta->afov = 42.5e-6;
            band_smeta->xfov = 42.5e-6;
            band_smeta->aoffset  = Along_Scan_Band_Offsets[0] / 1.0e6;
            band_smeta->xoffset  = Across_Scan_Band_Offsets[0] / 1.0e6;
            band_smeta->xscan    = band_smeta->xfov * (band_smeta->nlines - 1.0);
            break;
        case 2:
            band_smeta->nsamps   = 6320.0;
            band_smeta->nlines   = 16.0;
            band_smeta->afov = 42.5e-6;
            band_smeta->xfov = 42.5e-6;
            band_smeta->aoffset  = Along_Scan_Band_Offsets[1] / 1.0e6;
            band_smeta->xoffset  = Across_Scan_Band_Offsets[1] / 1.0e6;
            band_smeta->xscan    = band_smeta->xfov * (band_smeta->nlines - 1.0);
            break;
        case 3:
            band_smeta->nsamps   = 6320.0;
            band_smeta->nlines   = 16.0;
            band_smeta->afov = 42.5e-6;
            band_smeta->xfov = 42.5e-6;
            band_smeta->aoffset  = Along_Scan_Band_Offsets[2] / 1.0e6;
            band_smeta->xoffset  = Across_Scan_Band_Offsets[2] / 1.0e6;
            band_smeta->xscan    = band_smeta->xfov * (band_smeta->nlines - 1.0);
            break;
        case 4:
            band_smeta->nsamps   = 6320.0;
            band_smeta->nlines   = 16.0;
            band_smeta->afov = 42.5e-6;
            band_smeta->xfov = 42.5e-6;
            band_smeta->aoffset  = Along_Scan_Band_Offsets[3] / 1.0e6;
            band_smeta->xoffset  = Across_Scan_Band_Offsets[3] / 1.0e6;
            band_smeta->xscan    = band_smeta->xfov * (band_smeta->nlines - 1.0);
            break;
        case 5:
            band_smeta->nsamps   = 6320.0;
            band_smeta->nlines   = 16.0;
            band_smeta->afov = 39.4e-6;
            band_smeta->xfov = 42.5e-6;
            band_smeta->aoffset  = Along_Scan_Band_Offsets[4] / 1.0e6;
            band_smeta->xoffset  = Across_Scan_Band_Offsets[4] / 1.0e6;
            band_smeta->xscan    = band_smeta->xfov * (band_smeta->nlines - 1.0);
            break;
        case 6:
            band_smeta->nsamps   = 3160.0;
            band_smeta->nlines   = 8.0;
            band_smeta->afov = 85.0e-6;
            band_smeta->xfov = 85.0e-6;
            band_smeta->aoffset  = Along_Scan_Band_Offsets[5] / 1.0e6;
            band_smeta->xoffset  = Across_Scan_Band_Offsets[5] / 1.0e6;
            band_smeta->xscan    = band_smeta->xfov * (band_smeta->nlines - 1.0);
            break;
        case 7:
            band_smeta->nsamps   = 6320.0;
            band_smeta->nlines   = 16.0;
            band_smeta->afov = 39.4e-6;
            band_smeta->xfov = 42.5e-6;
            band_smeta->aoffset  = Along_Scan_Band_Offsets[6] / 1.0e6;
            band_smeta->xoffset  = Across_Scan_Band_Offsets[6] / 1.0e6;
            band_smeta->xscan    = band_smeta->xfov * (band_smeta->nlines - 1.0);
            break;
        case 8:
            band_smeta->nsamps   = 12640.0;
            band_smeta->nlines   = 32.0;
            band_smeta->afov = 18.5e-6;
            band_smeta->xfov = 21.25e-6;
            band_smeta->aoffset  = Along_Scan_Band_Offsets[7] / 1.0e6;
            band_smeta->xoffset  = Across_Scan_Band_Offsets[7] / 1.0e6;
            band_smeta->xscan    = band_smeta->xfov * (band_smeta->nlines - 1.0);
            break;
        default:
            IAS_LOG_ERROR("No LOS model for user band number %d.", band_smeta->band);
            return(ERROR);
    }

    return(SUCCESS);
}

int meta_write_angfile(
    char		*root_filename,		/* Output root file name                     */
    short		*sat_zn,		/* Array of satellite zenith angles          */
    short		*sat_az,		/* Array of satellite azimuth angles         */
    short		*sun_zn,		/* Array of solar zenith angles              */
    short		*sun_az,		/* Array of solar azimuth angles             */
    META_FRAME		*frame )		/* Output image framing information          */
{
    FILE		*ofp;			/* Output file pointer                       */
    char		ang_filename[PATH_MAX];	/* Output angle file name                    */
    int			count;			/* Total number of samples                   */

    /* Construct satellite view angle output file name */
    sprintf( ang_filename, "%s_V%02d.img", root_filename, frame->band );
    printf("Writing view angle band file %s.\n", ang_filename);

    /* Open output file */
    if ( (ofp = fopen( ang_filename, "wb" )) == NULL )
    {
        IAS_LOG_ERROR("Opening output view angle band file %s.", ang_filename);
        return(ERROR);
    }

    /* Calculate the total number of samples */
    count = frame->nlines * frame->nsamps;

    /* Write the Satellite Zenith Angle layer */
    if ( fwrite( sat_zn, sizeof(short), count, ofp ) != count )
    {
        IAS_LOG_ERROR("Writing satellite zenith angle layer for band %d.", frame->band);
        fclose(ofp);
        return(ERROR);
    }

    /* Write the Satellite Azimuth Angle layer */
    if ( fwrite( sat_az, sizeof(short), count, ofp ) != count )
    {
        IAS_LOG_ERROR("Writing satellite azimuth angle layer for band %d.", frame->band);
        fclose(ofp);
        return(ERROR);
    }

    /* Close the output image file */
    fclose(ofp);

    /* Create the output header file name */
    strcat( ang_filename, ".hdr" );
    printf("Writing view angle band header file %s.\n", ang_filename);

    /* Open the output header file */
    if ( (ofp = fopen( ang_filename, "w" )) == NULL )
    {
        IAS_LOG_ERROR("Opening output ENVI header file %s.", ang_filename);
        return(ERROR);
    }

    /* Write the output header file */
    fprintf( ofp, "ENVI\n" );
    fprintf( ofp, "description = {\n" );
    fprintf( ofp, "  L8 View Angle Band File for %s.}\n", root_filename );
    fprintf( ofp, "samples = %d\n", frame->nsamps );
    fprintf( ofp, "lines   = %d\n", frame->nlines );
    fprintf( ofp, "bands   = 2\n" );
    fprintf( ofp, "header offset = 0\n" );
    fprintf( ofp, "file type = ENVI Standard\n" );
    fprintf( ofp, "data type = 2\n" );
    fprintf( ofp, "interleave = bsq\n" );
    fprintf( ofp, "sensor type = Unknown\n" );
    fprintf( ofp, "byte order = 0\n" );
    if ( frame->code == 1 )
    {
        fprintf( ofp, "map info = {UTM, 1.500, 1.500, %6.3lf, %6.3lf, %6.3lf, %6.3lf, %d, North, WGS-84, units=Meters}\n",
                       frame->ul_x, frame->ul_y, frame->pixsize, frame->pixsize, frame->zone );
    }
    else if ( frame->code == 6 )
    {
        fprintf( ofp, "map info = {Polar Stereographic, 1.500, 1.500, %6.3lf, %6.3lf, %6.3lf, %6.3lf, WGS-84, units=Meters}\n",
                       frame->ul_x, frame->ul_y, frame->pixsize, frame->pixsize );
        fprintf( ofp, "projection info = {31, 6378137.000, 6356752.314, -71.000000, 0.000000, 0.0, 0.0, WGS-84, Polar Stereographic, units=Meters}\n" );
    }
    else
    {
        IAS_LOG_ERROR("Invalid map projection, not UTM or LIMA PS");
        return(ERROR);
    }
    fprintf( ofp, "wavelength units = Unknown\n" );

    /* Close the output header file */
    fclose(ofp);

    /* Construct solar angle output file name */
    sprintf( ang_filename, "%s_S%02d.img", root_filename, frame->band );
    printf("Writing sun angle band file %s.\n", ang_filename);

    /* Open output file */
    if ( (ofp = fopen( ang_filename, "wb" )) == NULL )
    {
        IAS_LOG_ERROR("Opening output sun angle band file %s.", ang_filename);
        return(ERROR);
    }

    /* Write the Solar Zenith Angle layer */
    if ( fwrite( sun_zn, sizeof(short), count, ofp ) != count )
    {
        IAS_LOG_ERROR("Writing solar zenith angle layer for band %d.", frame->band);
        fclose(ofp);
        return(ERROR);
    }

    /* Write the Solar Azimuth Angle layer */
    if ( fwrite( sun_az, sizeof(short), count, ofp ) != count )
    {
        IAS_LOG_ERROR("Writing solar azimuth angle layer for band %d.", frame->band);
        fclose(ofp);
        return(ERROR);
    }

    /* Close the output image file */
    fclose(ofp);

    /* Create the output header file name */
    strcat( ang_filename, ".hdr" );
    printf("Writing sun angle band header file %s.\n", ang_filename);

    /* Open the output header file */
    if ( (ofp = fopen( ang_filename, "w" )) == NULL )
    {
        IAS_LOG_ERROR("Opening output ENVI header file %s.", ang_filename);
        return(ERROR);
    }

    /* Write the output header file */
    fprintf( ofp, "ENVI\n" );
    fprintf( ofp, "description = {\n" );
    fprintf( ofp, "  L8 Sun Angle Band File for %s.}\n", root_filename );
    fprintf( ofp, "samples = %d\n", frame->nsamps );
    fprintf( ofp, "lines   = %d\n", frame->nlines );
    fprintf( ofp, "bands   = 2\n" );
    fprintf( ofp, "header offset = 0\n" );
    fprintf( ofp, "file type = ENVI Standard\n" );
    fprintf( ofp, "data type = 2\n" );
    fprintf( ofp, "interleave = bsq\n" );
    fprintf( ofp, "sensor type = Unknown\n" );
    fprintf( ofp, "byte order = 0\n" );
    if ( frame->code == 1 )
    {
        fprintf( ofp, "map info = {UTM, 1.500, 1.500, %6.3lf, %6.3lf, %6.3lf, %6.3lf, %d, North, WGS-84, units=Meters}\n",
                       frame->ul_x, frame->ul_y, frame->pixsize, frame->pixsize, frame->zone );
    }
    else if ( frame->code == 6 )
    {
        fprintf( ofp, "map info = {Polar Stereographic, 1.500, 1.500, %6.3lf, %6.3lf, %6.3lf, %6.3lf, WGS-84, units=Meters}\n",
                       frame->ul_x, frame->ul_y, frame->pixsize, frame->pixsize );
        fprintf( ofp, "projection info = {31, 6378137.000, 6356752.314, -71.000000, 0.000000, 0.0, 0.0, WGS-84, Polar Stereographic, units=Meters}\n" );
    }
    else
    {
        IAS_LOG_ERROR("Invalid map projection, not UTM or LIMA PS");
        return(ERROR);
    }
    fprintf( ofp, "wavelength units = Unknown\n" );

    /* Close the output header file */
    fclose(ofp);

    return(SUCCESS);
}

int delta_date(
  int date1[3],                         /* Base date year, month, day */
  int date2[3] )                        /* Final date year, month, day */
{
    struct tm   d1;                     /* Time structure for base date */
    struct tm   d2;                     /* Time structure for final date */
    time_t      t1;                     /* Seconds from epoch for base date */
    time_t      t2;                     /* Seconds from epoch for final date */
    double      secs;                   /* Seconds elapsed */
    int         days;                   /* Days elapsed */

    d1.tm_sec   = 0;
    d1.tm_min   = 0;
    d1.tm_hour  = 0;
    d1.tm_mday  = date1[2];
    d1.tm_mon   = date1[1] - 1;
    d1.tm_year  = date1[0] - 1900;
    d1.tm_wday  = -1;
    d1.tm_yday  = -1;
    d1.tm_isdst = 0;
    d2.tm_sec   = 0;
    d2.tm_min   = 0;
    d2.tm_hour  = 0;
    d2.tm_mday  = date2[2];
    d2.tm_mon   = date2[1] - 1;
    d2.tm_year  = date2[0] - 1900;
    d2.tm_wday  = -1;
    d2.tm_yday  = -1;
    d2.tm_isdst = 0;

    t1 = mktime( &d1 );
    t2 = mktime( &d2 );

    secs = difftime( t2, t1 );
    days = (int)floor( secs / 86400.0 + 0.5 );

    return( days );
}
